umf-access 0.1.0.dev8__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.
- umf_access/__init__.py +109 -0
- umf_access/adoption.py +41 -0
- umf_access/build/__init__.py +2 -0
- umf_access/build/approximate.py +34 -0
- umf_access/build/catalog.py +1626 -0
- umf_access/build/commands.py +394 -0
- umf_access/build/pg_privileges.py +1544 -0
- umf_access/build/privileges.py +134 -0
- umf_access/build/search.py +365 -0
- umf_access/build/unity_search.py +104 -0
- umf_access/bulk.py +227 -0
- umf_access/canonical.py +23 -0
- umf_access/capture.py +410 -0
- umf_access/catalog.py +325 -0
- umf_access/codec_support.py +427 -0
- umf_access/commands.py +93 -0
- umf_access/delta_read.py +758 -0
- umf_access/dsl/__init__.py +148 -0
- umf_access/dsl/_context.py +36 -0
- umf_access/dsl/_expressions.py +625 -0
- umf_access/dsl/_joined.py +4 -0
- umf_access/dsl/_nodes.py +207 -0
- umf_access/dsl/_query.py +5559 -0
- umf_access/dsl/_selection.py +143 -0
- umf_access/dsl/navigation.py +302 -0
- umf_access/dsl/render.py +516 -0
- umf_access/dsl/search.py +343 -0
- umf_access/engine_catalog.py +563 -0
- umf_access/generated_core.py +5 -0
- umf_access/lifecycle/__init__.py +46 -0
- umf_access/lifecycle/_darwin_process_observer.c +306 -0
- umf_access/lifecycle/approval.py +366 -0
- umf_access/lifecycle/backfills.py +79 -0
- umf_access/lifecycle/catalog.py +289 -0
- umf_access/lifecycle/cli.py +231 -0
- umf_access/lifecycle/concurrent.py +196 -0
- umf_access/lifecycle/conversion_policy.py +188 -0
- umf_access/lifecycle/correspondence.py +203 -0
- umf_access/lifecycle/generation_authority_bootstrap.py +1491 -0
- umf_access/lifecycle/generation_authority_session.py +125 -0
- umf_access/lifecycle/generation_enrollment_authority.py +1108 -0
- umf_access/lifecycle/generation_enrollment_ledger.py +698 -0
- umf_access/lifecycle/generation_ingress.py +185 -0
- umf_access/lifecycle/generation_root_registry.py +138 -0
- umf_access/lifecycle/head.py +250 -0
- umf_access/lifecycle/head_view.py +81 -0
- umf_access/lifecycle/host.py +1183 -0
- umf_access/lifecycle/ingress_custody.py +750 -0
- umf_access/lifecycle/ingress_local_postgres.py +7990 -0
- umf_access/lifecycle/ingress_store.py +1488 -0
- umf_access/lifecycle/ledger.py +276 -0
- umf_access/lifecycle/ledger_schema.py +116 -0
- umf_access/lifecycle/mixed.py +593 -0
- umf_access/lifecycle/outcome_schema.py +136 -0
- umf_access/lifecycle/owner_approval_core.py +1810 -0
- umf_access/lifecycle/owner_authority.py +472 -0
- umf_access/lifecycle/owner_bootstrap.py +2077 -0
- umf_access/lifecycle/owner_wire.py +161 -0
- umf_access/lifecycle/phase_fence.py +52 -0
- umf_access/lifecycle/phase_policy.py +422 -0
- umf_access/lifecycle/privileges.py +145 -0
- umf_access/lifecycle/probe.py +39 -0
- umf_access/lifecycle/progress.py +497 -0
- umf_access/lifecycle/roles.py +96 -0
- umf_access/lifecycle/row_originals.py +1712 -0
- umf_access/lifecycle/row_originals_creation.py +759 -0
- umf_access/lifecycle/row_originals_receipt.py +413 -0
- umf_access/lifecycle/seeds.py +99 -0
- umf_access/lifecycle/sql_containment.py +358 -0
- umf_access/lifecycle/sql_containment_cli.py +33 -0
- umf_access/lifecycle/sql_containment_parser.py +20 -0
- umf_access/lifecycle/supervisor_journal_codec.py +1251 -0
- umf_access/lifecycle/table_boundary.py +22 -0
- umf_access/lifecycle/target_custody_codec.py +788 -0
- umf_access/lifecycle/witness.py +72 -0
- umf_access/managed_actions.py +271 -0
- umf_access/managed_bulk.py +353 -0
- umf_access/managed_delta.py +150 -0
- umf_access/managed_support.py +166 -0
- umf_access/manifest_commands.py +278 -0
- umf_access/native_actions.py +1007 -0
- umf_access/native_program.py +570 -0
- umf_access/pages.py +125 -0
- umf_access/postgres_bulk.py +509 -0
- umf_access/postgres_read.py +1230 -0
- umf_access/postgres_search.py +639 -0
- umf_access/protocols.py +665 -0
- umf_access/py.typed +0 -0
- umf_access/related_keys.py +233 -0
- umf_access/reviewed.py +706 -0
- umf_access/search_catalog.py +122 -0
- umf_access/targets.py +312 -0
- umf_access/types.py +220 -0
- umf_access/unified/__init__.py +187 -0
- umf_access/unified/_binding.py +654 -0
- umf_access/unified/head_session.py +144 -0
- umf_access/unified/native_binding.py +143 -0
- umf_access/unified/operation_values.py +173 -0
- umf_access/unified/outcome_values.py +76 -0
- umf_access/unified/session_async.py +161 -0
- umf_access/unified/session_binding.py +108 -0
- umf_access/unified/session_policy.py +152 -0
- umf_access/unified/session_psycopg2.py +70 -0
- umf_access/unified/session_sqlalchemy.py +161 -0
- umf_access/unified/session_sync.py +148 -0
- umf_access/unified/table_reads.py +314 -0
- umf_access/unified/table_writes.py +193 -0
- umf_access/unity_search.py +312 -0
- umf_access/values.py +280 -0
- umf_access/verification.py +64 -0
- umf_access-0.1.0.dev8.dist-info/METADATA +15 -0
- umf_access-0.1.0.dev8.dist-info/RECORD +117 -0
- umf_access-0.1.0.dev8.dist-info/WHEEL +4 -0
- umf_access-0.1.0.dev8.dist-info/entry_points.txt +4 -0
- umf_access-0.1.0.dev8.dist-info/licenses/LICENSE-APACHE +201 -0
- umf_access-0.1.0.dev8.dist-info/licenses/LICENSE-MIT +21 -0
- umf_access-0.1.0.dev8.dist-info/licenses/LICENSE.md +239 -0
umf_access/catalog.py
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
"""Inert precompiled read catalogs. No discovery, filesystem or compiler imports."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from collections.abc import AsyncGenerator, Awaitable, Generator, Mapping
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from typing import Any, cast
|
|
9
|
+
|
|
10
|
+
from pydantic import BaseModel, TypeAdapter
|
|
11
|
+
|
|
12
|
+
from .adoption import TargetIdentity
|
|
13
|
+
from .codec_support import revalidate_model, validate_graph
|
|
14
|
+
from .dsl import Continuation, RelatedKeys, SortValue, WithKeys
|
|
15
|
+
from .dsl import Page as Page # noqa: PLC0414 -- explicit public ABI re-export
|
|
16
|
+
from .pages import ReadContinuation, ReadPage, StaleContinuation
|
|
17
|
+
from .protocols import AsyncReadTarget, ReadTarget
|
|
18
|
+
from .reviewed import CatalogRead
|
|
19
|
+
from .types import MISSING, StrictModel, Vector
|
|
20
|
+
from .values import validate_vector
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class CatalogError(ValueError):
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class NotCompiledForTarget(CatalogError):
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class QueryNotFound(LookupError):
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class QueryNotUnique(ValueError):
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass(frozen=True)
|
|
40
|
+
class TargetPin:
|
|
41
|
+
kind: str
|
|
42
|
+
backend_id: str
|
|
43
|
+
backend_version: str
|
|
44
|
+
target_profile: str
|
|
45
|
+
binding_sha256: str
|
|
46
|
+
platform: tuple[tuple[str, tuple[str, ...]], ...]
|
|
47
|
+
|
|
48
|
+
def matches(self, identity: TargetIdentity) -> bool:
|
|
49
|
+
return (
|
|
50
|
+
(
|
|
51
|
+
identity.kind,
|
|
52
|
+
identity.backend_id,
|
|
53
|
+
identity.backend_version,
|
|
54
|
+
identity.target_profile,
|
|
55
|
+
identity.binding_sha256,
|
|
56
|
+
)
|
|
57
|
+
== (
|
|
58
|
+
self.kind,
|
|
59
|
+
self.backend_id,
|
|
60
|
+
self.backend_version,
|
|
61
|
+
self.target_profile,
|
|
62
|
+
self.binding_sha256,
|
|
63
|
+
)
|
|
64
|
+
and len(identity.platform) == len(self.platform)
|
|
65
|
+
and all(
|
|
66
|
+
name in dict(self.platform) and version in dict(self.platform)[name]
|
|
67
|
+
for name, version in identity.platform
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@dataclass(frozen=True)
|
|
73
|
+
class Argument:
|
|
74
|
+
name: str
|
|
75
|
+
annotation: Any
|
|
76
|
+
optional: bool = False
|
|
77
|
+
key_model: type[StrictModel] | None = None
|
|
78
|
+
|
|
79
|
+
def validate(self, value: object) -> object:
|
|
80
|
+
if value is MISSING:
|
|
81
|
+
if self.optional:
|
|
82
|
+
return value
|
|
83
|
+
raise CatalogError("required argument missing")
|
|
84
|
+
if self.key_model is not None and value is not None:
|
|
85
|
+
if type(value) is not self.key_model:
|
|
86
|
+
raise CatalogError("argument requires its exact declared Key type")
|
|
87
|
+
return revalidate_model(self.key_model, cast(StrictModel, value))
|
|
88
|
+
if self.annotation == Vector:
|
|
89
|
+
if type(value) is not tuple:
|
|
90
|
+
raise CatalogError("exact immutable Vector carrier required")
|
|
91
|
+
return validate_vector(value, dimensions=len(value) if value else 1)
|
|
92
|
+
return TypeAdapter(self.annotation).validate_python(value, strict=True)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@dataclass(frozen=True)
|
|
96
|
+
class ReadVariant:
|
|
97
|
+
presence: tuple[str, ...]
|
|
98
|
+
pin: TargetPin
|
|
99
|
+
entry: CatalogRead[Any, Any]
|
|
100
|
+
# Native parameter name, original argument, optional exact Key component.
|
|
101
|
+
parameters: tuple[tuple[str, str, str | None], ...]
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@dataclass(frozen=True)
|
|
105
|
+
class ReadPlan:
|
|
106
|
+
name: str
|
|
107
|
+
terminal: str
|
|
108
|
+
arguments: tuple[Argument, ...]
|
|
109
|
+
variants: tuple[ReadVariant, ...]
|
|
110
|
+
tuple_fields: tuple[str, ...] = ()
|
|
111
|
+
cursor_argument: str | None = None
|
|
112
|
+
cursor_key_model: type[StrictModel] | None = None
|
|
113
|
+
key_components: tuple[tuple[str, int], ...] = ()
|
|
114
|
+
related_field: str | None = None
|
|
115
|
+
related_row_model: type[BaseModel] | None = None
|
|
116
|
+
|
|
117
|
+
def bind(
|
|
118
|
+
self, target: ReadTarget | AsyncReadTarget, values: Mapping[str, object]
|
|
119
|
+
) -> tuple[ReadVariant, BaseModel, ReadContinuation | None]:
|
|
120
|
+
if set(values) != {a.name for a in self.arguments}:
|
|
121
|
+
raise CatalogError("exact catalog argument inventory required")
|
|
122
|
+
checked = {
|
|
123
|
+
a.name: (
|
|
124
|
+
values[a.name]
|
|
125
|
+
if a.name == self.cursor_argument
|
|
126
|
+
else a.validate(values[a.name])
|
|
127
|
+
)
|
|
128
|
+
for a in self.arguments
|
|
129
|
+
}
|
|
130
|
+
after = checked.get(self.cursor_argument) if self.cursor_argument else None
|
|
131
|
+
if after is not None:
|
|
132
|
+
if (
|
|
133
|
+
not isinstance(after, Continuation)
|
|
134
|
+
or self.cursor_key_model is None
|
|
135
|
+
or type(after.key) is not self.cursor_key_model
|
|
136
|
+
):
|
|
137
|
+
raise StaleContinuation(
|
|
138
|
+
"page requires its original declared-Key continuation"
|
|
139
|
+
)
|
|
140
|
+
key = revalidate_model(self.cursor_key_model, after.key)
|
|
141
|
+
if any(
|
|
142
|
+
index >= len(after.sort_values)
|
|
143
|
+
or getattr(key, name) != after.sort_values[index]
|
|
144
|
+
for name, index in self.key_components
|
|
145
|
+
):
|
|
146
|
+
raise StaleContinuation(
|
|
147
|
+
"continuation Key differs from its complete sort context"
|
|
148
|
+
)
|
|
149
|
+
after = ReadContinuation(
|
|
150
|
+
after.sort_values,
|
|
151
|
+
after.identity_digest,
|
|
152
|
+
after.owner_cursor,
|
|
153
|
+
after.snapshot_versions,
|
|
154
|
+
)
|
|
155
|
+
presence = tuple(
|
|
156
|
+
a.name
|
|
157
|
+
for a in self.arguments
|
|
158
|
+
if a.optional and checked[a.name] is not MISSING
|
|
159
|
+
)
|
|
160
|
+
for candidate in self.variants:
|
|
161
|
+
candidate.entry.artifact()
|
|
162
|
+
identity = target.identity()
|
|
163
|
+
candidates = [
|
|
164
|
+
v
|
|
165
|
+
for v in self.variants
|
|
166
|
+
if v.presence == presence and v.pin.matches(identity)
|
|
167
|
+
]
|
|
168
|
+
if len(candidates) != 1:
|
|
169
|
+
raise NotCompiledForTarget(
|
|
170
|
+
"no unique compiled variant for target identity and argument presence"
|
|
171
|
+
)
|
|
172
|
+
variant = candidates[0]
|
|
173
|
+
variant.entry.artifact() # Loaded generation/runtime pins checked before target dispatch.
|
|
174
|
+
native = {
|
|
175
|
+
name: (
|
|
176
|
+
getattr(checked[source], component)
|
|
177
|
+
if component is not None
|
|
178
|
+
else checked[source]
|
|
179
|
+
)
|
|
180
|
+
for name, source, component in variant.parameters
|
|
181
|
+
}
|
|
182
|
+
return (
|
|
183
|
+
variant,
|
|
184
|
+
variant.entry.parameters.model_validate(native, strict=True),
|
|
185
|
+
cast(ReadContinuation | None, after),
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _row(plan: ReadPlan, row: object) -> object:
|
|
190
|
+
result: object
|
|
191
|
+
if plan.tuple_fields:
|
|
192
|
+
result = tuple(getattr(row, name) for name in plan.tuple_fields)
|
|
193
|
+
elif plan.related_field is not None:
|
|
194
|
+
if plan.related_row_model is None:
|
|
195
|
+
raise CatalogError("original related row model required")
|
|
196
|
+
result = validate_graph(plan.related_row_model, {name: getattr(row, name) for name in plan.related_row_model.model_fields})
|
|
197
|
+
else:
|
|
198
|
+
result = row
|
|
199
|
+
if plan.related_field is not None:
|
|
200
|
+
keys = getattr(row, plan.related_field)
|
|
201
|
+
if not isinstance(keys, RelatedKeys):
|
|
202
|
+
raise CatalogError("original decoded related-Key collection required")
|
|
203
|
+
return WithKeys(result, keys)
|
|
204
|
+
return result
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _finish(plan: ReadPlan, rows: list[Any]) -> object:
|
|
208
|
+
if plan.terminal == "exists":
|
|
209
|
+
return bool(rows)
|
|
210
|
+
if plan.terminal == "count":
|
|
211
|
+
if len(rows) != 1:
|
|
212
|
+
raise CatalogError("count requires exactly one native result")
|
|
213
|
+
return rows[0].count
|
|
214
|
+
if plan.terminal == "first":
|
|
215
|
+
return _row(plan, rows[0]) if rows else None
|
|
216
|
+
if plan.terminal in ("one", "get"):
|
|
217
|
+
if not rows:
|
|
218
|
+
raise QueryNotFound("catalog query returned no row")
|
|
219
|
+
if len(rows) != 1:
|
|
220
|
+
raise QueryNotUnique("catalog query returned multiple rows")
|
|
221
|
+
return _row(plan, rows[0])
|
|
222
|
+
return [_row(plan, row) for row in rows]
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
async def _await_rows(plan: ReadPlan, answer: Awaitable[list[Any]]) -> object:
|
|
226
|
+
return _finish(plan, await answer)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def _page(plan: ReadPlan, page: ReadPage[Any]) -> Page[Any, Any]:
|
|
230
|
+
after = None
|
|
231
|
+
if page.next_after is not None:
|
|
232
|
+
if plan.cursor_key_model is None or not plan.key_components:
|
|
233
|
+
raise CatalogError("compiled page has no exact Key metadata")
|
|
234
|
+
original = page.next_after
|
|
235
|
+
key = plan.cursor_key_model.model_validate(
|
|
236
|
+
{name: original.values[index] for name, index in plan.key_components},
|
|
237
|
+
strict=True,
|
|
238
|
+
)
|
|
239
|
+
after = Continuation(
|
|
240
|
+
key,
|
|
241
|
+
cast(tuple[SortValue, ...], original.values),
|
|
242
|
+
original.identity_digest,
|
|
243
|
+
original.owner_cursor,
|
|
244
|
+
original.snapshot_versions,
|
|
245
|
+
)
|
|
246
|
+
return Page(tuple(_row(plan, row) for row in page.items), after)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
async def _await_page(
|
|
250
|
+
plan: ReadPlan, answer: Awaitable[ReadPage[Any]]
|
|
251
|
+
) -> Page[Any, Any]:
|
|
252
|
+
return _page(plan, await answer)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def run_query(
|
|
256
|
+
plan: ReadPlan,
|
|
257
|
+
target: ReadTarget | AsyncReadTarget,
|
|
258
|
+
arguments: Mapping[str, object],
|
|
259
|
+
*,
|
|
260
|
+
timeout: Any = None,
|
|
261
|
+
) -> object:
|
|
262
|
+
variant, parameters, after = plan.bind(target, arguments)
|
|
263
|
+
if plan.terminal == "page":
|
|
264
|
+
page = target.page(variant.entry, parameters, after=after, timeout=timeout)
|
|
265
|
+
return (
|
|
266
|
+
_await_page(plan, page)
|
|
267
|
+
if isinstance(page, Awaitable)
|
|
268
|
+
else _page(plan, page)
|
|
269
|
+
)
|
|
270
|
+
answer = target.read(variant.entry, parameters, timeout=timeout)
|
|
271
|
+
if isinstance(answer, Awaitable):
|
|
272
|
+
return _await_rows(plan, answer)
|
|
273
|
+
return _finish(plan, answer)
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def run_stream(
|
|
277
|
+
plan: ReadPlan,
|
|
278
|
+
target: ReadTarget | AsyncReadTarget,
|
|
279
|
+
arguments: Mapping[str, object],
|
|
280
|
+
*,
|
|
281
|
+
max_rows: int,
|
|
282
|
+
page_size: int | None = None,
|
|
283
|
+
timeout: Any = None,
|
|
284
|
+
) -> object:
|
|
285
|
+
variant, parameters, after = plan.bind(target, arguments)
|
|
286
|
+
if plan.terminal != "page" or after is not None:
|
|
287
|
+
raise CatalogError("exports require an initial catalog page declaration")
|
|
288
|
+
if page_size is not None and (
|
|
289
|
+
type(page_size) is not int or not 1 <= page_size <= 1000
|
|
290
|
+
):
|
|
291
|
+
raise ValueError("page_size must be an integer from 1 through 1000")
|
|
292
|
+
stream = target.stream(
|
|
293
|
+
variant.entry,
|
|
294
|
+
parameters,
|
|
295
|
+
max_rows=max_rows,
|
|
296
|
+
timeout=timeout,
|
|
297
|
+
**({"page_size": page_size} if page_size is not None else {}),
|
|
298
|
+
)
|
|
299
|
+
if not plan.tuple_fields and plan.related_field is None:
|
|
300
|
+
return stream
|
|
301
|
+
return (
|
|
302
|
+
_async_tuple_stream(plan, cast(AsyncGenerator[Any, None], stream))
|
|
303
|
+
if hasattr(stream, "__aiter__")
|
|
304
|
+
else _tuple_stream(plan, cast(Generator[Any, None, None], stream))
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def _tuple_stream(
|
|
309
|
+
plan: ReadPlan, stream: Generator[Any, None, None]
|
|
310
|
+
) -> Generator[object, None, None]:
|
|
311
|
+
try:
|
|
312
|
+
for row in stream:
|
|
313
|
+
yield _row(plan, row)
|
|
314
|
+
finally:
|
|
315
|
+
stream.close()
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
async def _async_tuple_stream(
|
|
319
|
+
plan: ReadPlan, stream: AsyncGenerator[Any, None]
|
|
320
|
+
) -> AsyncGenerator[object, None]:
|
|
321
|
+
try:
|
|
322
|
+
async for row in stream:
|
|
323
|
+
yield _row(plan, row)
|
|
324
|
+
finally:
|
|
325
|
+
await stream.aclose()
|