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
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
"""Inert typed search catalog and bounded result assembly; no compiler imports."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from collections.abc import Awaitable, Mapping
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from datetime import timedelta
|
|
9
|
+
from typing import Any, Protocol, TypeVar
|
|
10
|
+
|
|
11
|
+
from pydantic import BaseModel
|
|
12
|
+
|
|
13
|
+
from .adoption import TargetIdentity
|
|
14
|
+
from .catalog import Argument, CatalogError, NotCompiledForTarget, TargetPin
|
|
15
|
+
from .dsl import Fusion, SearchResult
|
|
16
|
+
from .native_program import NativeProgram
|
|
17
|
+
from .types import MISSING, StrictModel
|
|
18
|
+
|
|
19
|
+
SEARCH_FILTER_PARAMETER_ABI = "umf.search-filter-parameters/0.1"
|
|
20
|
+
|
|
21
|
+
R = TypeVar("R")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True)
|
|
25
|
+
class SearchEntry:
|
|
26
|
+
program: NativeProgram
|
|
27
|
+
result: type[BaseModel]
|
|
28
|
+
key_model: type[StrictModel]
|
|
29
|
+
query_argument: str
|
|
30
|
+
embed: bool = False
|
|
31
|
+
tuple_fields: tuple[str, ...] = ()
|
|
32
|
+
parameter_aliases: tuple[tuple[str, str], ...] = ()
|
|
33
|
+
|
|
34
|
+
def artifact(self) -> dict[str, Any]:
|
|
35
|
+
program = self.program.checked()
|
|
36
|
+
if program["version"] not in ("weft.search/0.1", "weft.search/0.2", "weft.unity-search/0.1"):
|
|
37
|
+
raise CatalogError("search owner program required")
|
|
38
|
+
if any(
|
|
39
|
+
getattr(model, "UMF_BUNDLE_INPUT_DIGEST", None)
|
|
40
|
+
!= self.program.bundle_input_digest
|
|
41
|
+
for model in (self.result, self.key_model)
|
|
42
|
+
):
|
|
43
|
+
raise CatalogError("CATALOG_STALE: mixed loaded search generation")
|
|
44
|
+
return program
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@dataclass(frozen=True)
|
|
48
|
+
class SearchVariant:
|
|
49
|
+
presence: tuple[str, ...]
|
|
50
|
+
pin: TargetPin
|
|
51
|
+
entries: tuple[SearchEntry, ...]
|
|
52
|
+
parameters: tuple[tuple[str, str, str | None], ...]
|
|
53
|
+
top_k: int
|
|
54
|
+
fusion: Fusion | None = None
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class SearchTarget(Protocol):
|
|
58
|
+
def identity(self) -> TargetIdentity: ...
|
|
59
|
+
def search(
|
|
60
|
+
self,
|
|
61
|
+
variant: SearchVariant,
|
|
62
|
+
parameters: Mapping[str, object],
|
|
63
|
+
*,
|
|
64
|
+
timeout: timedelta | None = None,
|
|
65
|
+
) -> SearchResult[Any]: ...
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class AsyncSearchTarget(Protocol):
|
|
69
|
+
def identity(self) -> TargetIdentity: ...
|
|
70
|
+
async def search(
|
|
71
|
+
self,
|
|
72
|
+
variant: SearchVariant,
|
|
73
|
+
parameters: Mapping[str, object],
|
|
74
|
+
*,
|
|
75
|
+
timeout: timedelta | None = None,
|
|
76
|
+
) -> SearchResult[Any]: ...
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@dataclass(frozen=True)
|
|
80
|
+
class SearchPlan:
|
|
81
|
+
name: str
|
|
82
|
+
arguments: tuple[Argument, ...]
|
|
83
|
+
variants: tuple[SearchVariant, ...]
|
|
84
|
+
|
|
85
|
+
def run(
|
|
86
|
+
self,
|
|
87
|
+
target: SearchTarget | AsyncSearchTarget,
|
|
88
|
+
values: Mapping[str, object],
|
|
89
|
+
*,
|
|
90
|
+
timeout: timedelta | None = None,
|
|
91
|
+
) -> SearchResult[Any] | Awaitable[SearchResult[Any]]:
|
|
92
|
+
if set(values) != {a.name for a in self.arguments}:
|
|
93
|
+
raise CatalogError("exact search argument inventory required")
|
|
94
|
+
checked = {a.name: a.validate(values[a.name]) for a in self.arguments}
|
|
95
|
+
presence = tuple(
|
|
96
|
+
a.name
|
|
97
|
+
for a in self.arguments
|
|
98
|
+
if a.optional and checked[a.name] is not MISSING
|
|
99
|
+
)
|
|
100
|
+
for candidate in self.variants:
|
|
101
|
+
for entry in candidate.entries:
|
|
102
|
+
entry.artifact()
|
|
103
|
+
identity = target.identity()
|
|
104
|
+
matching = [
|
|
105
|
+
v
|
|
106
|
+
for v in self.variants
|
|
107
|
+
if v.presence == presence and v.pin.matches(identity)
|
|
108
|
+
]
|
|
109
|
+
if len(matching) != 1:
|
|
110
|
+
raise NotCompiledForTarget(
|
|
111
|
+
"no unique compiled search variant for target and presence"
|
|
112
|
+
)
|
|
113
|
+
variant = matching[0]
|
|
114
|
+
for entry in variant.entries:
|
|
115
|
+
entry.artifact()
|
|
116
|
+
native = {
|
|
117
|
+
name: getattr(checked[source], component)
|
|
118
|
+
if component is not None
|
|
119
|
+
else checked[source]
|
|
120
|
+
for name, source, component in variant.parameters
|
|
121
|
+
}
|
|
122
|
+
return target.search(variant, native, timeout=timeout)
|
umf_access/targets.py
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
"""Host-owned PostgreSQL/Lakebase sync and async read targets.
|
|
3
|
+
|
|
4
|
+
Every call uses the same checked catalog program and native admission boundary.
|
|
5
|
+
Connections, credentials and application schema selection remain with the host.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import hashlib
|
|
11
|
+
import json
|
|
12
|
+
import math
|
|
13
|
+
from collections.abc import AsyncGenerator, Generator
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from datetime import timedelta
|
|
16
|
+
from typing import Any, TypeVar
|
|
17
|
+
|
|
18
|
+
from pydantic import BaseModel
|
|
19
|
+
|
|
20
|
+
from .adoption import TargetIdentity
|
|
21
|
+
from .pages import ReadObligationUnmet
|
|
22
|
+
from .postgres_read import (
|
|
23
|
+
ReadContinuation,
|
|
24
|
+
ReadPage,
|
|
25
|
+
TimedOut,
|
|
26
|
+
execute_page,
|
|
27
|
+
execute_page_async,
|
|
28
|
+
execute_read,
|
|
29
|
+
execute_read_async,
|
|
30
|
+
execute_stream,
|
|
31
|
+
execute_stream_async,
|
|
32
|
+
verify_read,
|
|
33
|
+
verify_read_async,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# Explicit public re-export is required by static consumers.
|
|
37
|
+
from .protocols import AsyncReadTarget as AsyncReadTarget # noqa: PLC0414
|
|
38
|
+
|
|
39
|
+
# Explicit public re-export is required by static consumers.
|
|
40
|
+
from .protocols import ReadTarget as ReadTarget # noqa: PLC0414
|
|
41
|
+
from .reviewed import CatalogRead
|
|
42
|
+
|
|
43
|
+
P = TypeVar("P", bound=BaseModel)
|
|
44
|
+
R = TypeVar("R", bound=BaseModel)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class TargetMismatch(ValueError):
|
|
48
|
+
pass
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class NotCompiledForTarget(ValueError):
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@dataclass(frozen=True)
|
|
56
|
+
class PostgresConfiguration:
|
|
57
|
+
app_schema: str
|
|
58
|
+
binding_sha256: str
|
|
59
|
+
server_versions: tuple[int, ...]
|
|
60
|
+
default_timeout: timedelta
|
|
61
|
+
backend_id: str = "weft-postgresql"
|
|
62
|
+
backend_version: str = "raw-read/0.1"
|
|
63
|
+
target_profile: str = "weft.raw-read/0.1"
|
|
64
|
+
|
|
65
|
+
def __post_init__(self) -> None:
|
|
66
|
+
if (
|
|
67
|
+
not self.app_schema
|
|
68
|
+
or not self.server_versions
|
|
69
|
+
or any(
|
|
70
|
+
type(v) is not int or not 180000 <= v < 190000
|
|
71
|
+
for v in self.server_versions
|
|
72
|
+
)
|
|
73
|
+
):
|
|
74
|
+
raise TargetMismatch(
|
|
75
|
+
"explicit application schema and pinned PostgreSQL18 versions required"
|
|
76
|
+
)
|
|
77
|
+
if len(self.binding_sha256) != 64 or any(
|
|
78
|
+
c not in "0123456789abcdef" for c in self.binding_sha256
|
|
79
|
+
):
|
|
80
|
+
raise TargetMismatch("exact binding SHA-256 required")
|
|
81
|
+
_milliseconds(self.default_timeout, self.default_timeout)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def binding_digest(binding: object) -> str:
|
|
85
|
+
return hashlib.sha256(
|
|
86
|
+
json.dumps(
|
|
87
|
+
binding,
|
|
88
|
+
ensure_ascii=False,
|
|
89
|
+
sort_keys=True,
|
|
90
|
+
separators=(",", ":"),
|
|
91
|
+
allow_nan=False,
|
|
92
|
+
).encode()
|
|
93
|
+
).hexdigest()
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _milliseconds(timeout: timedelta | None, default: timedelta) -> int:
|
|
97
|
+
value = default if timeout is None else timeout
|
|
98
|
+
if (
|
|
99
|
+
type(value) is not timedelta
|
|
100
|
+
or not math.isfinite(value.total_seconds())
|
|
101
|
+
or value.total_seconds() < 0
|
|
102
|
+
):
|
|
103
|
+
raise ValueError("positive finite target deadline required")
|
|
104
|
+
if value.total_seconds() == 0:
|
|
105
|
+
raise TimedOut("deadline expired before dispatch")
|
|
106
|
+
milliseconds = math.ceil(value.total_seconds() * 1000)
|
|
107
|
+
if milliseconds > 2_147_483_647:
|
|
108
|
+
raise ValueError("deadline exceeds native PostgreSQL timeout bound")
|
|
109
|
+
return milliseconds
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class _PostgresBase:
|
|
113
|
+
kind = "postgresql"
|
|
114
|
+
profile = "postgresql18"
|
|
115
|
+
|
|
116
|
+
def __init__(
|
|
117
|
+
self,
|
|
118
|
+
connection: Any,
|
|
119
|
+
configuration: PostgresConfiguration,
|
|
120
|
+
catalog_entries: tuple[CatalogRead[Any, Any], ...] = (),
|
|
121
|
+
):
|
|
122
|
+
self.connection, self.configuration, self.catalog_entries = (
|
|
123
|
+
connection,
|
|
124
|
+
configuration,
|
|
125
|
+
catalog_entries,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
def identity(self) -> TargetIdentity:
|
|
129
|
+
version = self.connection.info.server_version
|
|
130
|
+
if version not in self.configuration.server_versions:
|
|
131
|
+
raise TargetMismatch(
|
|
132
|
+
"native server version is outside the qualified pinned set"
|
|
133
|
+
)
|
|
134
|
+
return TargetIdentity(
|
|
135
|
+
self.kind,
|
|
136
|
+
self.configuration.backend_id,
|
|
137
|
+
self.configuration.backend_version,
|
|
138
|
+
self.configuration.target_profile,
|
|
139
|
+
self.configuration.binding_sha256,
|
|
140
|
+
(("postgresql", str(version)),),
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
def _admit(self, entry: CatalogRead[P, R], timeout: timedelta | None) -> int:
|
|
144
|
+
milliseconds = _milliseconds(timeout, self.configuration.default_timeout)
|
|
145
|
+
self.identity()
|
|
146
|
+
artifact = entry.artifact()
|
|
147
|
+
if (
|
|
148
|
+
artifact["target"] != self.profile
|
|
149
|
+
or binding_digest(artifact["binding"]) != self.configuration.binding_sha256
|
|
150
|
+
):
|
|
151
|
+
raise NotCompiledForTarget(
|
|
152
|
+
"entry target or binding differs from host target"
|
|
153
|
+
)
|
|
154
|
+
return milliseconds
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class PostgresTarget(_PostgresBase):
|
|
158
|
+
def verify(self) -> None:
|
|
159
|
+
self.identity()
|
|
160
|
+
if not self.catalog_entries:
|
|
161
|
+
raise TargetMismatch(
|
|
162
|
+
"explicit catalog entries required for eager verification"
|
|
163
|
+
)
|
|
164
|
+
for entry in self.catalog_entries:
|
|
165
|
+
try:
|
|
166
|
+
verify_read(
|
|
167
|
+
self.connection,
|
|
168
|
+
entry,
|
|
169
|
+
app_schema=self.configuration.app_schema,
|
|
170
|
+
target=self.profile,
|
|
171
|
+
timeout_ms=self._admit(entry, None),
|
|
172
|
+
)
|
|
173
|
+
except ReadObligationUnmet as error:
|
|
174
|
+
raise TargetMismatch(str(error)) from error
|
|
175
|
+
|
|
176
|
+
def read(
|
|
177
|
+
self,
|
|
178
|
+
entry: CatalogRead[P, R],
|
|
179
|
+
parameters: P,
|
|
180
|
+
*,
|
|
181
|
+
timeout: timedelta | None = None,
|
|
182
|
+
) -> list[R]:
|
|
183
|
+
return execute_read(
|
|
184
|
+
self.connection,
|
|
185
|
+
entry,
|
|
186
|
+
parameters,
|
|
187
|
+
app_schema=self.configuration.app_schema,
|
|
188
|
+
target=self.profile,
|
|
189
|
+
timeout_ms=self._admit(entry, timeout),
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
def page(
|
|
193
|
+
self,
|
|
194
|
+
entry: CatalogRead[P, R],
|
|
195
|
+
parameters: P,
|
|
196
|
+
*,
|
|
197
|
+
after: ReadContinuation | None = None,
|
|
198
|
+
timeout: timedelta | None = None,
|
|
199
|
+
) -> ReadPage[R]:
|
|
200
|
+
return execute_page(
|
|
201
|
+
self.connection,
|
|
202
|
+
entry,
|
|
203
|
+
parameters,
|
|
204
|
+
app_schema=self.configuration.app_schema,
|
|
205
|
+
target=self.profile,
|
|
206
|
+
after=after,
|
|
207
|
+
timeout_ms=self._admit(entry, timeout),
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
def stream(
|
|
211
|
+
self,
|
|
212
|
+
entry: CatalogRead[P, R],
|
|
213
|
+
parameters: P,
|
|
214
|
+
*,
|
|
215
|
+
max_rows: int,
|
|
216
|
+
page_size: int | None = None,
|
|
217
|
+
timeout: timedelta | None = None,
|
|
218
|
+
) -> Generator[R, None, None]:
|
|
219
|
+
return execute_stream(
|
|
220
|
+
self.connection,
|
|
221
|
+
entry,
|
|
222
|
+
parameters,
|
|
223
|
+
app_schema=self.configuration.app_schema,
|
|
224
|
+
target=self.profile,
|
|
225
|
+
max_rows=max_rows,
|
|
226
|
+
page_size=page_size,
|
|
227
|
+
timeout_ms=self._admit(entry, timeout),
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
class LakebaseTarget(PostgresTarget):
|
|
232
|
+
kind = "lakebase"
|
|
233
|
+
profile = "lakebase18"
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
class AsyncPostgresTarget(_PostgresBase):
|
|
237
|
+
async def verify(self) -> None:
|
|
238
|
+
self.identity()
|
|
239
|
+
if not self.catalog_entries:
|
|
240
|
+
raise TargetMismatch(
|
|
241
|
+
"explicit catalog entries required for eager verification"
|
|
242
|
+
)
|
|
243
|
+
for entry in self.catalog_entries:
|
|
244
|
+
try:
|
|
245
|
+
await verify_read_async(
|
|
246
|
+
self.connection,
|
|
247
|
+
entry,
|
|
248
|
+
app_schema=self.configuration.app_schema,
|
|
249
|
+
target=self.profile,
|
|
250
|
+
timeout_ms=self._admit(entry, None),
|
|
251
|
+
)
|
|
252
|
+
except ReadObligationUnmet as error:
|
|
253
|
+
raise TargetMismatch(str(error)) from error
|
|
254
|
+
|
|
255
|
+
async def read(
|
|
256
|
+
self,
|
|
257
|
+
entry: CatalogRead[P, R],
|
|
258
|
+
parameters: P,
|
|
259
|
+
*,
|
|
260
|
+
timeout: timedelta | None = None,
|
|
261
|
+
) -> list[R]:
|
|
262
|
+
return await execute_read_async(
|
|
263
|
+
self.connection,
|
|
264
|
+
entry,
|
|
265
|
+
parameters,
|
|
266
|
+
app_schema=self.configuration.app_schema,
|
|
267
|
+
target=self.profile,
|
|
268
|
+
timeout_ms=self._admit(entry, timeout),
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
async def page(
|
|
272
|
+
self,
|
|
273
|
+
entry: CatalogRead[P, R],
|
|
274
|
+
parameters: P,
|
|
275
|
+
*,
|
|
276
|
+
after: ReadContinuation | None = None,
|
|
277
|
+
timeout: timedelta | None = None,
|
|
278
|
+
) -> ReadPage[R]:
|
|
279
|
+
return await execute_page_async(
|
|
280
|
+
self.connection,
|
|
281
|
+
entry,
|
|
282
|
+
parameters,
|
|
283
|
+
app_schema=self.configuration.app_schema,
|
|
284
|
+
target=self.profile,
|
|
285
|
+
after=after,
|
|
286
|
+
timeout_ms=self._admit(entry, timeout),
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
def stream(
|
|
290
|
+
self,
|
|
291
|
+
entry: CatalogRead[P, R],
|
|
292
|
+
parameters: P,
|
|
293
|
+
*,
|
|
294
|
+
max_rows: int,
|
|
295
|
+
page_size: int | None = None,
|
|
296
|
+
timeout: timedelta | None = None,
|
|
297
|
+
) -> AsyncGenerator[R, None]:
|
|
298
|
+
return execute_stream_async(
|
|
299
|
+
self.connection,
|
|
300
|
+
entry,
|
|
301
|
+
parameters,
|
|
302
|
+
app_schema=self.configuration.app_schema,
|
|
303
|
+
target=self.profile,
|
|
304
|
+
max_rows=max_rows,
|
|
305
|
+
page_size=page_size,
|
|
306
|
+
timeout_ms=self._admit(entry, timeout),
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
class AsyncLakebaseTarget(AsyncPostgresTarget):
|
|
311
|
+
kind = "lakebase"
|
|
312
|
+
profile = "lakebase18"
|
umf_access/types.py
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
"""Shared generated-model ABI. Imports perform no host operations."""
|
|
3
|
+
|
|
4
|
+
import re
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import TYPE_CHECKING, ClassVar, Generic, TypeAlias, TypeVar, final
|
|
7
|
+
|
|
8
|
+
# Explicit public re-export is required by static consumers.
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
# Both supported releases expose this static alias to the same sentinel.
|
|
11
|
+
from pydantic.experimental.missing_sentinel import MISSING as MISSING # noqa: PLC0414 -- explicit public re-export for static consumers
|
|
12
|
+
else:
|
|
13
|
+
try:
|
|
14
|
+
from pydantic import MISSING as MISSING # noqa: PLC0414 -- explicit public re-export for static consumers
|
|
15
|
+
except ImportError:
|
|
16
|
+
from pydantic.experimental.missing_sentinel import MISSING as MISSING # noqa: PLC0414 -- explicit public re-export for static consumers
|
|
17
|
+
from pydantic import BaseModel, ConfigDict
|
|
18
|
+
|
|
19
|
+
from .generated_core import CURRENT_CORE_VERSION, CoreVersion
|
|
20
|
+
|
|
21
|
+
RUNTIME_ABI = "umf-access-runtime/0.1"
|
|
22
|
+
RUNTIME_IDENTITY = ("umf_access", "0.1.0.dev0", "umf-access-runtime/0.1")
|
|
23
|
+
|
|
24
|
+
Vector: TypeAlias = tuple[float, ...]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ValueRuleError(ValueError):
|
|
28
|
+
"""A carrier or authored constraint refused; messages contain no values."""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class CodecError(ValueError):
|
|
32
|
+
"""A codec boundary refused its value graph or column inventory."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class StrictModel(BaseModel):
|
|
36
|
+
"""Generated classes inherit directly, then seal their own subclass hook.
|
|
37
|
+
|
|
38
|
+
Literal defaults belong to the engine, never to this base. Codecs must
|
|
39
|
+
revalidate raw attributes even though assignment is frozen.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
UMF_FINAL: ClassVar[bool] = False
|
|
43
|
+
UMF_KEY: ClassVar[bool] = False
|
|
44
|
+
|
|
45
|
+
def __init_subclass__(cls, **kwargs: object) -> None:
|
|
46
|
+
if any(base.__dict__.get("UMF_FINAL", False) for base in cls.__bases__):
|
|
47
|
+
raise TypeError("generated model is final")
|
|
48
|
+
super().__init_subclass__(**kwargs)
|
|
49
|
+
|
|
50
|
+
@classmethod
|
|
51
|
+
def __pydantic_init_subclass__(cls, **kwargs: object) -> None:
|
|
52
|
+
super().__pydantic_init_subclass__(**kwargs)
|
|
53
|
+
if cls.UMF_KEY:
|
|
54
|
+
type.__setattr__(cls, "__hash__", None)
|
|
55
|
+
|
|
56
|
+
model_config = ConfigDict(
|
|
57
|
+
strict=True,
|
|
58
|
+
extra="forbid",
|
|
59
|
+
frozen=True,
|
|
60
|
+
revalidate_instances="always",
|
|
61
|
+
hide_input_in_errors=True,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# Preserve the published generic parameter spelling and variance.
|
|
66
|
+
InputT = TypeVar("InputT", bound=StrictModel, covariant=True) # noqa: PLC0105
|
|
67
|
+
# Preserve the published generic parameter spelling and variance.
|
|
68
|
+
OutputT = TypeVar("OutputT", covariant=True) # noqa: PLC0105
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _is_model_type(value: object, *, allow_none: bool = False) -> bool:
|
|
72
|
+
return isinstance(value, type) and (
|
|
73
|
+
allow_none and value is type(None) or issubclass(value, StrictModel)
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@final
|
|
78
|
+
@dataclass(frozen=True)
|
|
79
|
+
class ActionProfile:
|
|
80
|
+
id: str
|
|
81
|
+
version: str
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@final
|
|
85
|
+
@dataclass(frozen=True)
|
|
86
|
+
class ActionSource:
|
|
87
|
+
"""Exact original document/declaration identity, never an authority token."""
|
|
88
|
+
|
|
89
|
+
document_id: str
|
|
90
|
+
core_version: CoreVersion
|
|
91
|
+
module: str
|
|
92
|
+
action: str
|
|
93
|
+
document_sha256: str
|
|
94
|
+
action_pointer: str
|
|
95
|
+
invocation_id: str
|
|
96
|
+
invocation_version: str
|
|
97
|
+
|
|
98
|
+
def __post_init__(self) -> None:
|
|
99
|
+
if any(
|
|
100
|
+
type(value) is not str or not value
|
|
101
|
+
for value in (
|
|
102
|
+
self.document_id,
|
|
103
|
+
self.core_version,
|
|
104
|
+
self.module,
|
|
105
|
+
self.action,
|
|
106
|
+
self.action_pointer,
|
|
107
|
+
self.invocation_id,
|
|
108
|
+
self.invocation_version,
|
|
109
|
+
)
|
|
110
|
+
):
|
|
111
|
+
raise ValueRuleError("complete original action source required")
|
|
112
|
+
if not re.fullmatch(r"[0-9a-f]{64}", self.document_sha256):
|
|
113
|
+
raise ValueRuleError("original document SHA-256 required")
|
|
114
|
+
if self.core_version != CURRENT_CORE_VERSION or (self.invocation_id, self.invocation_version) != ("umf.actions.tx", "1"):
|
|
115
|
+
raise ValueRuleError("unsupported original action source profile")
|
|
116
|
+
if not self.action_pointer.startswith("/modules/"):
|
|
117
|
+
raise ValueRuleError("original action pointer required")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
# Read-only aliases retain the earlier source view while canonical dataclass
|
|
121
|
+
# fields follow the executor ABI and support dataclasses.replace.
|
|
122
|
+
@property
|
|
123
|
+
def documentId(self) -> str:
|
|
124
|
+
return self.document_id
|
|
125
|
+
|
|
126
|
+
@property
|
|
127
|
+
def coreVersion(self) -> str:
|
|
128
|
+
return self.core_version
|
|
129
|
+
|
|
130
|
+
@property
|
|
131
|
+
def documentSha256(self) -> str:
|
|
132
|
+
return self.document_sha256
|
|
133
|
+
|
|
134
|
+
@property
|
|
135
|
+
def actionPointer(self) -> str:
|
|
136
|
+
return self.action_pointer
|
|
137
|
+
|
|
138
|
+
@property
|
|
139
|
+
def invocation(self) -> ActionProfile:
|
|
140
|
+
return ActionProfile(self.invocation_id, self.invocation_version)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
@final
|
|
144
|
+
@dataclass(frozen=True)
|
|
145
|
+
class KeyTypeRef:
|
|
146
|
+
module: str
|
|
147
|
+
element: str
|
|
148
|
+
key: str
|
|
149
|
+
model: type[StrictModel]
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@final
|
|
153
|
+
@dataclass(frozen=True)
|
|
154
|
+
class RecordTypeRef:
|
|
155
|
+
module: str
|
|
156
|
+
element: str
|
|
157
|
+
model: type[StrictModel]
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
@final
|
|
161
|
+
@dataclass(frozen=True)
|
|
162
|
+
class ActionRef(Generic[InputT, OutputT]):
|
|
163
|
+
"""Immutable generated action identity and value types; never an executor."""
|
|
164
|
+
|
|
165
|
+
module: str
|
|
166
|
+
action: str
|
|
167
|
+
input_type: type[InputT]
|
|
168
|
+
output_type: type[OutputT]
|
|
169
|
+
source: ActionSource
|
|
170
|
+
input_fields: tuple[tuple[str, str], ...] = ()
|
|
171
|
+
key_types: tuple[KeyTypeRef, ...] = ()
|
|
172
|
+
record_types: tuple[RecordTypeRef, ...] = ()
|
|
173
|
+
|
|
174
|
+
def __post_init__(self) -> None:
|
|
175
|
+
if any(
|
|
176
|
+
type(value) is not str or not value for value in (self.module, self.action)
|
|
177
|
+
):
|
|
178
|
+
raise ValueRuleError("action identity requires nonempty schema IDs")
|
|
179
|
+
if type(self.source) is not ActionSource or (self.module, self.action) != (self.source.module, self.source.action):
|
|
180
|
+
raise ValueRuleError("action reference/source identity mismatch")
|
|
181
|
+
if type(self.input_fields) is not tuple or len({field[0] for field in self.input_fields})!=len(self.input_fields) or len({field[1] for field in self.input_fields})!=len(self.input_fields):
|
|
182
|
+
raise ValueRuleError("distinct immutable action input metadata required")
|
|
183
|
+
if self.input_fields and {python for _, python in self.input_fields} != set(
|
|
184
|
+
self.input_type.model_fields
|
|
185
|
+
):
|
|
186
|
+
raise ValueRuleError("complete source/Python input correspondence required")
|
|
187
|
+
if type(self.key_types) is not tuple or type(self.record_types) is not tuple:
|
|
188
|
+
raise ValueRuleError("immutable action model correspondence required")
|
|
189
|
+
if not _is_model_type(self.input_type):
|
|
190
|
+
raise TypeError("action input requires a strict generated model type")
|
|
191
|
+
if not _is_model_type(self.output_type, allow_none=True):
|
|
192
|
+
raise TypeError(
|
|
193
|
+
"action output requires a strict generated model type or None"
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
def __init_subclass__(cls, **kwargs: object) -> None:
|
|
197
|
+
raise TypeError("action references are final")
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
SnapshotVersions = tuple[tuple[str, str, int], ...]
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def validate_snapshot_versions(value: SnapshotVersions) -> None:
|
|
204
|
+
"""Validate inert, canonical native snapshot metadata; never authority."""
|
|
205
|
+
if type(value) is not tuple:
|
|
206
|
+
raise TypeError("immutable original snapshot version vector required")
|
|
207
|
+
names = set()
|
|
208
|
+
for item in value:
|
|
209
|
+
if (
|
|
210
|
+
type(item) is not tuple or len(item) != 3
|
|
211
|
+
or type(item[0]) is not str or not item[0] or "\x00" in item[0]
|
|
212
|
+
or type(item[1]) is not str or not item[1] or "\x00" in item[1]
|
|
213
|
+
or type(item[2]) is not int or item[2] < 0
|
|
214
|
+
or item[0] in names
|
|
215
|
+
):
|
|
216
|
+
raise TypeError("distinct native table/UUID/nonnegative version records required")
|
|
217
|
+
names.add(item[0])
|
|
218
|
+
if value != tuple(sorted(value)):
|
|
219
|
+
raise TypeError("canonical native snapshot version ordering required")
|
|
220
|
+
|