1"""
2``syside.query``: read-only queries over a loaded model.
3
4Use this package to ask questions about a model that :func:`syside.load_model`
5has produced: find elements by name or metadata, walk generalization and
6containment hierarchies, and inspect features, connections, and variation
7points. No function here modifies the model.
8
9Three kinds of names are exported:
10
11* Traversal primitives (:func:`get_specialized_elements`, :func:`find_specializing_elements`,
12 and :func:`walk_containment`), which walk the type and ownership
13 hierarchies.
14* Query functions built on those primitives, such as :func:`find_by_name` and
15 :func:`find_by_type`. The model-wide lookups search the documents the
16 model itself loaded, or the model's and environment's documents of the
17 given ``tiers`` (:class:`syside.DocumentTier`, e.g.
18 :data:`PROJECT_TIERS`), or with ``scope`` only one element's subtree, and
19 drop library elements under ``LibraryElementFilter.EXCLUDE``.
20* Index types (:class:`NameIndex`, :class:`TypeIndex`, :class:`MetadataIndex`)
21 with matching ``build_*_index`` builders. Without an index, each query scans
22 the model; when you repeat lookups, build the index once and pass it via the
23 ``index=`` parameter to make each later lookup a dictionary read. An index
24 never changes a query's result, only its cost.
25
26Every function returns a plain, fully materialized value (a ``list``,
27``set``, ``bool``, scalar, or ``None``), never a lazy view of the model.
28
29The ``get_`` and ``find_`` prefixes mark **worst-case cost**, not miss behavior
30(both return ``None`` on a miss). A ``get_*`` call never looks beyond the
31element it is handed: its cost is linear in path depth (:func:`get_by_path`)
32or in that element's own relationships, never in the size of a model,
33document or subtree. A ``find_*`` call may search: its worst case is linear in
34the scope it searches. The prefix names the worst case, not every call;
35:mod:`syside.query._functions` gives each lookup's cost. The accessors of the
36high-level API, in :mod:`syside.experimental.query`, follow the same rule.
37"""
38
39from __future__ import annotations
40
41from syside.query._functions import (
42 ALL_TIERS,
43 PROJECT_TIERS,
44 LibraryElementFilter,
45 LibraryElements,
46 find_by_type,
47 get_declared_member,
48 MetadataIndex,
49 MultiplicityBounds,
50 NameIndex,
51 TypeIndex,
52 UNBOUNDED,
53 Unbounded,
54 actors,
55 declared_actors,
56 containers,
57 annotated_elements,
58 find_annotating_elements,
59 build_metadata_index,
60 build_name_index,
61 build_type_index,
62 contains,
63 contents,
64 connection_ends,
65 find_bindings_of,
66 cross_subsets,
67 find_features_crossing_through,
68 find_types_with_feature,
69 find_features_with_featuring_type,
70 all_contents,
71 scan_all_contents,
72 description,
73 declared_types_of,
74 all_types_of,
75 documentation,
76 enumeration_values,
77 exposed_elements,
78 feature_chain,
79 featured_in,
80 features_of,
81 find_by_name,
82 find_by_name_and_type,
83 find_by_qualified_name,
84 get_by_path,
85 find_elements_of_type,
86 find_metadata_usages,
87 find_relationships,
88 has_metadata_prefix,
89 find_connectors_of,
90 find_connectors_to,
91 find_connectors_from,
92 inherited_features,
93 is_contained_in,
94 metadata_prefixes,
95 metadata_usages,
96 multiplicity_bounds,
97 implicit_multiplicity_bounds,
98 generalization_names,
99 find_redefining_features,
100 redefined_by,
101 redefines,
102 referenced_feature,
103 siblings,
104 specializes,
105 superclassifiers,
106 subject_of,
107 declared_subject_of,
108 subsets,
109 find_subclassifiers,
110 specializations,
111 subclassifiers,
112 supertypes,
113 textual_representation,
114 variants,
115)
116from syside.query._primitives import (
117 find_specializing_elements,
118 generalizations,
119 get_specialized_elements,
120 walk_containment,
121)
122
123__all__ = [
124 # primitives
125 "get_specialized_elements",
126 "generalizations",
127 "find_specializing_elements",
128 "specializations",
129 "walk_containment",
130 # lookup scope
131 "ALL_TIERS",
132 "PROJECT_TIERS",
133 "LibraryElementFilter",
134 "LibraryElements",
135 # index types + builders
136 "NameIndex",
137 "TypeIndex",
138 "MetadataIndex",
139 "build_name_index",
140 "build_type_index",
141 "build_metadata_index",
142 # dataclasses
143 "MultiplicityBounds",
144 "Unbounded",
145 "UNBOUNDED",
146 # lookup
147 "get_declared_member",
148 "find_by_name",
149 "find_by_type",
150 "find_by_name_and_type",
151 "find_by_qualified_name",
152 "get_by_path",
153 "find_elements_of_type",
154 "find_relationships",
155 "find_metadata_usages",
156 # ownership tree
157 "contents",
158 "scan_all_contents",
159 "all_contents",
160 "containers",
161 "siblings",
162 "is_contained_in",
163 "contains",
164 # feature / type structure
165 "features_of",
166 "inherited_features",
167 "generalization_names",
168 "declared_types_of",
169 "all_types_of",
170 "supertypes",
171 "find_subclassifiers",
172 "subclassifiers",
173 "subsets",
174 "redefines",
175 "find_redefining_features",
176 "redefined_by",
177 "superclassifiers",
178 "featured_in",
179 "cross_subsets",
180 "find_features_crossing_through",
181 "find_types_with_feature",
182 "find_features_with_featuring_type",
183 "specializes",
184 # connections
185 "connection_ends",
186 "find_connectors_of",
187 "find_connectors_to",
188 "find_connectors_from",
189 "find_bindings_of",
190 # expressions / chains
191 "referenced_feature",
192 "feature_chain",
193 # documentation
194 "documentation",
195 "description",
196 "textual_representation",
197 # metadata
198 "metadata_prefixes",
199 "metadata_usages",
200 "has_metadata_prefix",
201 "annotated_elements",
202 "find_annotating_elements",
203 # enumerations / variants / cases
204 "enumeration_values",
205 "variants",
206 "actors",
207 "declared_actors",
208 "subject_of",
209 "declared_subject_of",
210 # multiplicity
211 "multiplicity_bounds",
212 "implicit_multiplicity_bounds",
213 # views
214 "exposed_elements",
215]