haiway 0.21.2__py3-none-any.whl → 0.21.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,6 @@
1
- from collections.abc import Callable, Collection, Iterable
1
+ import re
2
+ import unicodedata
3
+ from collections.abc import Callable, Collection, Iterable, Sequence, Set
2
4
  from typing import Any, Literal, Self, cast, final
3
5
 
4
6
  from haiway.state.path import AttributePath
@@ -66,6 +68,83 @@ class AttributeRequirement[Root]:
66
68
  check=check_equal,
67
69
  )
68
70
 
71
+ @classmethod
72
+ def text_match[Parameter](
73
+ cls,
74
+ value: str,
75
+ /,
76
+ path: AttributePath[Root, str] | str,
77
+ ) -> Self:
78
+ """
79
+ Create a requirement that performs text matching on an attribute.
80
+
81
+ Parameters
82
+ ----------
83
+ value : str
84
+ The search term (can contain multiple words separated by spaces/punctuation)
85
+ path : AttributePath[Root, str] | str
86
+ The path to the string attribute to search in
87
+
88
+ Returns
89
+ -------
90
+ Self
91
+ A new requirement instance
92
+
93
+ Raises
94
+ ------
95
+ AssertionError
96
+ If path is not an AttributePath
97
+ """
98
+ assert isinstance( # nosec: B101
99
+ path, AttributePath
100
+ ), "Prepare attribute path by using Self._.path.to.property or explicitly"
101
+
102
+ def check_like(root: Root) -> None:
103
+ checked: Any = cast(AttributePath[Root, str], path)(root)
104
+ if not isinstance(checked, str):
105
+ raise ValueError(
106
+ f"Attribute value must be a string for like operation, got {type(checked)}"
107
+ f" for '{path.__repr__()}'"
108
+ )
109
+
110
+ # Perform full text search with proper Unicode support and word boundaries
111
+ def tokenize_text(text: str) -> Sequence[str]:
112
+ # Normalize and case-fold the text
113
+ normalized = unicodedata.normalize("NFC", text).casefold()
114
+ # Split on word boundaries and filter out empty strings
115
+ # re.UNICODE handles international characters, multiline text works by default
116
+ tokens = re.findall(r"\b\w+\b", normalized, re.UNICODE)
117
+ return tokens
118
+
119
+ # Tokenize both search terms and target text
120
+ search_tokens: Sequence[str] = tokenize_text(value)
121
+ target_tokens: Sequence[str] = tokenize_text(checked)
122
+ target_tokens_set: Set[str] = set(target_tokens)
123
+
124
+ # Check if all search tokens are found as complete words in target text
125
+ missing_terms = [
126
+ original_term
127
+ for original_term, token in zip(
128
+ value.split(),
129
+ search_tokens,
130
+ strict=False,
131
+ )
132
+ if token not in target_tokens_set
133
+ ]
134
+
135
+ if missing_terms:
136
+ raise ValueError(
137
+ f"Text search failed: '{checked}' is not like '{value}'. "
138
+ f"Missing tokens: {missing_terms} for '{path.__repr__()}'"
139
+ )
140
+
141
+ return cls(
142
+ path,
143
+ "like",
144
+ value,
145
+ check=check_like,
146
+ )
147
+
69
148
  @classmethod
70
149
  def not_equal[Parameter](
71
150
  cls,
@@ -266,6 +345,7 @@ class AttributeRequirement[Root]:
266
345
  lhs: Any,
267
346
  operator: Literal[
268
347
  "equal",
348
+ "like",
269
349
  "not_equal",
270
350
  "contains",
271
351
  "contains_any",
@@ -298,6 +378,7 @@ class AttributeRequirement[Root]:
298
378
  )
299
379
  self.operator: Literal[
300
380
  "equal",
381
+ "like",
301
382
  "not_equal",
302
383
  "contains",
303
384
  "contains_any",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: haiway
3
- Version: 0.21.2
3
+ Version: 0.21.3
4
4
  Summary: Framework for dependency injection and state management within structured concurrency model.
5
5
  Project-URL: Homepage, https://miquido.com
6
6
  Project-URL: Repository, https://github.com/miquido/haiway.git
@@ -22,7 +22,7 @@ haiway/opentelemetry/observability.py,sha256=5fsHsFgjcxUcA0hIOM18lVvVdYSRO91ER52
22
22
  haiway/state/__init__.py,sha256=AaMqlMhO4zKS_XNevy3A7BHh5PxmguA-Sk_FnaNDY1Q,355
23
23
  haiway/state/attributes.py,sha256=sububiFP23aBB8RGk6OvTUp7BEY6S0kER_uHC09yins,26733
24
24
  haiway/state/path.py,sha256=bv5MI3HmUyku78k0Sz5lc7Q_Bay53iom1l3AL5KZs-4,32143
25
- haiway/state/requirement.py,sha256=NbXL7JrB-zGE6KShcRRtq-wJbKu5lHlhFdmfhyJZdkc,12797
25
+ haiway/state/requirement.py,sha256=uj-mezofTEPDXUuvlHreIjy5Ya-Hig8TR8VE6R8wdyY,15611
26
26
  haiway/state/structure.py,sha256=KKIId-mrHAzGjYKKlvnlscMijVZVM8nDLnAwCFn1sTc,23259
27
27
  haiway/state/validation.py,sha256=eDOZKRrfd-dmdbqoHcLacdCVKmVCEpwt239EG6ljNF8,23557
28
28
  haiway/types/__init__.py,sha256=jFr5kf36SvVGdgngvik6_HzG8YNa3NVsdDDSqxVuGm4,281
@@ -39,7 +39,7 @@ haiway/utils/mimic.py,sha256=xaZiUKp096QFfdSw7cNIKEWt2UIS7vf880KF54gny38,1831
39
39
  haiway/utils/noop.py,sha256=U8ocfoCgt-pY0owJDPtrRrj53cabeIXH9qCKWMQnoRk,1336
40
40
  haiway/utils/queue.py,sha256=6v2u3pA6A44IuCCTOjmCt3yLyOcm7PCRnrIGo25j-1o,6402
41
41
  haiway/utils/stream.py,sha256=lXaeveTY0-AYG5xVzcQYaiC6SUD5fUtHoMXiQcrQAAM,5723
42
- haiway-0.21.2.dist-info/METADATA,sha256=9mHlQYan6RnsCcixkZBb8lt2v4SSNTV3q6_8u_X5uFE,4919
43
- haiway-0.21.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
44
- haiway-0.21.2.dist-info/licenses/LICENSE,sha256=3phcpHVNBP8jsi77gOO0E7rgKeDeu99Pi7DSnK9YHoQ,1069
45
- haiway-0.21.2.dist-info/RECORD,,
42
+ haiway-0.21.3.dist-info/METADATA,sha256=iUkk5Z8qoOqq41SjzBEkBlhoFEeBO_eO6pns1C0W08I,4919
43
+ haiway-0.21.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
44
+ haiway-0.21.3.dist-info/licenses/LICENSE,sha256=3phcpHVNBP8jsi77gOO0E7rgKeDeu99Pi7DSnK9YHoQ,1069
45
+ haiway-0.21.3.dist-info/RECORD,,