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/protocols.py
ADDED
|
@@ -0,0 +1,665 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
"""Action execution ABI. Hosts supply executors; this module performs no I/O.
|
|
3
|
+
|
|
4
|
+
Original JSON and transport bytes are retained exactly. Recovery custody is an
|
|
5
|
+
opaque host object and never becomes serializable authority in this carrier.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
from collections.abc import AsyncGenerator, Awaitable, Generator, Mapping
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
from datetime import timedelta
|
|
14
|
+
from math import isfinite
|
|
15
|
+
from typing import Any, Generic, Protocol, TypeVar, cast, overload, runtime_checkable
|
|
16
|
+
|
|
17
|
+
from pydantic import BaseModel
|
|
18
|
+
|
|
19
|
+
from .adoption import TargetIdentity
|
|
20
|
+
from .codec_support import revalidate_model
|
|
21
|
+
from .pages import ReadContinuation, ReadPage
|
|
22
|
+
from .reviewed import CatalogRead
|
|
23
|
+
from .types import MISSING, ActionRef, StrictModel
|
|
24
|
+
|
|
25
|
+
InputT = TypeVar("InputT", bound=StrictModel)
|
|
26
|
+
OutputT = TypeVar("OutputT")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass(frozen=True)
|
|
30
|
+
class OriginalOutcome:
|
|
31
|
+
action: ActionRef[StrictModel, object]
|
|
32
|
+
result_json: str = field(repr=False)
|
|
33
|
+
request_json: str = field(repr=False)
|
|
34
|
+
recovery: object = field(repr=False)
|
|
35
|
+
transport: bytes | None = field(default=None, repr=False)
|
|
36
|
+
|
|
37
|
+
def __post_init__(self) -> None:
|
|
38
|
+
if self.action.source is None:
|
|
39
|
+
raise ValueError("original source-bound action required")
|
|
40
|
+
for text in (self.result_json, self.request_json):
|
|
41
|
+
if type(text) is not str or len(text.encode("utf-8")) > 4_194_304:
|
|
42
|
+
raise ValueError("bounded original JSON required")
|
|
43
|
+
if not isinstance(json.loads(text), dict):
|
|
44
|
+
# The protocol reports invalid JSON carrier values uniformly as ValueError.
|
|
45
|
+
raise ValueError("original object required") # noqa: TRY004
|
|
46
|
+
if self.transport is not None and type(self.transport) is not bytes:
|
|
47
|
+
raise TypeError("immutable original transport required")
|
|
48
|
+
|
|
49
|
+
def result(self) -> dict[str, object]:
|
|
50
|
+
# A fresh view cannot mutate the retained original bytes/string.
|
|
51
|
+
return cast(dict[str, object], json.loads(self.result_json))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@dataclass(frozen=True)
|
|
55
|
+
class Receipt:
|
|
56
|
+
store: str
|
|
57
|
+
epoch: str
|
|
58
|
+
version: str
|
|
59
|
+
|
|
60
|
+
def __post_init__(self) -> None:
|
|
61
|
+
if any(
|
|
62
|
+
type(v) is not str or not v for v in (self.store, self.epoch, self.version)
|
|
63
|
+
):
|
|
64
|
+
raise ValueError("complete original receipt required")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@dataclass(frozen=True)
|
|
68
|
+
class NativeOutcomeDetails:
|
|
69
|
+
"""Original native-profile evidence; never a tx/1 result or replay authority."""
|
|
70
|
+
|
|
71
|
+
action: ActionRef[StrictModel, object]
|
|
72
|
+
profile: str
|
|
73
|
+
markers_json: str = field(repr=False)
|
|
74
|
+
no_op: bool | None
|
|
75
|
+
verification_json: str | None = field(repr=False)
|
|
76
|
+
changes_json: str | None = field(repr=False)
|
|
77
|
+
attribution_json: str | None = field(repr=False)
|
|
78
|
+
receipt: Receipt | None
|
|
79
|
+
transaction_json: str = field(repr=False)
|
|
80
|
+
request_json: str = field(repr=False)
|
|
81
|
+
recovery: object = field(repr=False)
|
|
82
|
+
|
|
83
|
+
def __post_init__(self) -> None:
|
|
84
|
+
if self.action.source is None or self.profile not in (
|
|
85
|
+
"umf.actions.native-sql/0.1",
|
|
86
|
+
"umf.actions.native-bulk/0.1",
|
|
87
|
+
"umf.actions.native-delta/0.1",
|
|
88
|
+
"umf.actions.native-delta-bulk/0.1",
|
|
89
|
+
"umf.actions.managed-delta/0.1",
|
|
90
|
+
"umf.actions.managed-delta-bulk/0.1",
|
|
91
|
+
):
|
|
92
|
+
raise ValueError("original source-bound native profile required")
|
|
93
|
+
for text in (
|
|
94
|
+
self.markers_json,
|
|
95
|
+
self.verification_json,
|
|
96
|
+
self.changes_json,
|
|
97
|
+
self.attribution_json,
|
|
98
|
+
self.transaction_json,
|
|
99
|
+
self.request_json,
|
|
100
|
+
):
|
|
101
|
+
if text is not None:
|
|
102
|
+
if type(text) is not str or len(text.encode("utf-8")) > 4_194_304:
|
|
103
|
+
raise ValueError("bounded original native evidence required")
|
|
104
|
+
json.loads(text)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
OutcomeDetails = OriginalOutcome | NativeOutcomeDetails
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@dataclass(frozen=True, init=False)
|
|
111
|
+
class Committed(Generic[OutputT]):
|
|
112
|
+
output: OutputT
|
|
113
|
+
receipt: Receipt
|
|
114
|
+
_created: tuple[StrictModel, ...]
|
|
115
|
+
_changed: tuple[StrictModel, ...]
|
|
116
|
+
original: OutcomeDetails
|
|
117
|
+
|
|
118
|
+
def __init__(
|
|
119
|
+
self,
|
|
120
|
+
output: OutputT,
|
|
121
|
+
receipt: Receipt,
|
|
122
|
+
created: tuple[StrictModel, ...] = (),
|
|
123
|
+
changed: tuple[StrictModel, ...] = (),
|
|
124
|
+
original: OutcomeDetails | None = None,
|
|
125
|
+
*,
|
|
126
|
+
_created: tuple[StrictModel, ...] | None = None,
|
|
127
|
+
_changed: tuple[StrictModel, ...] | None = None,
|
|
128
|
+
):
|
|
129
|
+
# dataclasses.replace supplies stored field names; preserve its complete
|
|
130
|
+
# Key inventory as well as the public constructor's positional ABI.
|
|
131
|
+
if original is None:
|
|
132
|
+
raise TypeError("complete original outcome required")
|
|
133
|
+
if _created is not None:
|
|
134
|
+
if created:
|
|
135
|
+
raise TypeError("duplicate created inventory")
|
|
136
|
+
created = _created
|
|
137
|
+
if _changed is not None:
|
|
138
|
+
if changed:
|
|
139
|
+
raise TypeError("duplicate changed inventory")
|
|
140
|
+
changed = _changed
|
|
141
|
+
object.__setattr__(self, "output", output)
|
|
142
|
+
object.__setattr__(self, "receipt", receipt)
|
|
143
|
+
object.__setattr__(self, "_created", created)
|
|
144
|
+
object.__setattr__(self, "_changed", changed)
|
|
145
|
+
object.__setattr__(self, "original", original)
|
|
146
|
+
|
|
147
|
+
@property
|
|
148
|
+
def created(self) -> tuple[StrictModel, ...]:
|
|
149
|
+
return self._created
|
|
150
|
+
|
|
151
|
+
@property
|
|
152
|
+
def changed(self) -> tuple[StrictModel, ...]:
|
|
153
|
+
return self._changed
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
C = TypeVar("C", bound=Committed[Any])
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
@dataclass(frozen=True)
|
|
160
|
+
class Rejected:
|
|
161
|
+
code: str
|
|
162
|
+
retryable: bool
|
|
163
|
+
original: OutcomeDetails
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@dataclass(frozen=True)
|
|
167
|
+
class Denied:
|
|
168
|
+
code: str
|
|
169
|
+
original: OutcomeDetails
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
@dataclass(frozen=True)
|
|
173
|
+
class Conflict:
|
|
174
|
+
retained: bool
|
|
175
|
+
code: str
|
|
176
|
+
original: OutcomeDetails
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
@dataclass(frozen=True)
|
|
180
|
+
class TimedOut:
|
|
181
|
+
original: OutcomeDetails
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
@dataclass(frozen=True)
|
|
185
|
+
class Indeterminate:
|
|
186
|
+
original: OutcomeDetails
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
@dataclass(frozen=True)
|
|
190
|
+
class Replayed:
|
|
191
|
+
outcome: Committed[object] | Rejected | Denied | Conflict
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
ActionOutcome = (
|
|
195
|
+
Committed[object]
|
|
196
|
+
| Rejected
|
|
197
|
+
| Denied
|
|
198
|
+
| Conflict
|
|
199
|
+
| TimedOut
|
|
200
|
+
| Indeterminate
|
|
201
|
+
| Replayed
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
@dataclass(frozen=True)
|
|
206
|
+
class ValidationFailure:
|
|
207
|
+
code: str
|
|
208
|
+
parameter: str | None = None
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
@dataclass(frozen=True)
|
|
212
|
+
class ValidationResult:
|
|
213
|
+
valid: bool
|
|
214
|
+
failures: tuple[ValidationFailure, ...]
|
|
215
|
+
complete: bool
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
@runtime_checkable
|
|
219
|
+
class ActionExecutor(Protocol):
|
|
220
|
+
def invoke(
|
|
221
|
+
self,
|
|
222
|
+
action: ActionRef[StrictModel, object],
|
|
223
|
+
input: Mapping[str, object],
|
|
224
|
+
*,
|
|
225
|
+
timeout: timedelta | None = None,
|
|
226
|
+
) -> ActionOutcome: ...
|
|
227
|
+
def validate(
|
|
228
|
+
self,
|
|
229
|
+
action: ActionRef[StrictModel, object],
|
|
230
|
+
input: Mapping[str, object],
|
|
231
|
+
*,
|
|
232
|
+
timeout: timedelta | None = None,
|
|
233
|
+
) -> ValidationResult: ...
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
@runtime_checkable
|
|
237
|
+
class ReplayingActionExecutor(ActionExecutor, Protocol):
|
|
238
|
+
def invoke_keyed(
|
|
239
|
+
self,
|
|
240
|
+
action: ActionRef[StrictModel, object],
|
|
241
|
+
input: Mapping[str, object],
|
|
242
|
+
*,
|
|
243
|
+
idempotency_key: str,
|
|
244
|
+
timeout: timedelta | None = None,
|
|
245
|
+
) -> ActionOutcome: ...
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
@runtime_checkable
|
|
249
|
+
class AsyncActionExecutor(Protocol):
|
|
250
|
+
async def invoke(
|
|
251
|
+
self,
|
|
252
|
+
action: ActionRef[StrictModel, object],
|
|
253
|
+
input: Mapping[str, object],
|
|
254
|
+
*,
|
|
255
|
+
timeout: timedelta | None = None,
|
|
256
|
+
) -> ActionOutcome: ...
|
|
257
|
+
async def validate(
|
|
258
|
+
self,
|
|
259
|
+
action: ActionRef[StrictModel, object],
|
|
260
|
+
input: Mapping[str, object],
|
|
261
|
+
*,
|
|
262
|
+
timeout: timedelta | None = None,
|
|
263
|
+
) -> ValidationResult: ...
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
@runtime_checkable
|
|
267
|
+
class AsyncReplayingActionExecutor(AsyncActionExecutor, Protocol):
|
|
268
|
+
async def invoke_keyed(
|
|
269
|
+
self,
|
|
270
|
+
action: ActionRef[StrictModel, object],
|
|
271
|
+
input: Mapping[str, object],
|
|
272
|
+
*,
|
|
273
|
+
idempotency_key: str,
|
|
274
|
+
timeout: timedelta | None = None,
|
|
275
|
+
) -> ActionOutcome: ...
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
# Preserve the published generic parameter spelling and variance.
|
|
279
|
+
ExecutorT = TypeVar( # noqa: PLC0105
|
|
280
|
+
"ExecutorT", bound=ActionExecutor | AsyncActionExecutor, covariant=True
|
|
281
|
+
)
|
|
282
|
+
# Preserve the published generic parameter spelling and variance.
|
|
283
|
+
ReplayingExecutorT = TypeVar( # noqa: PLC0105
|
|
284
|
+
"ReplayingExecutorT",
|
|
285
|
+
bound=ReplayingActionExecutor | AsyncReplayingActionExecutor,
|
|
286
|
+
covariant=True,
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
class ActionError(RuntimeError):
|
|
291
|
+
def __init__(self, code: str, original: OutcomeDetails | None = None):
|
|
292
|
+
self.code, self.original = code, original
|
|
293
|
+
super().__init__("action result: " + code)
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
class ActionRefused(ActionError):
|
|
297
|
+
pass
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
class ActionDenied(ActionError):
|
|
301
|
+
pass
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
class ActionTimedOut(ActionError):
|
|
305
|
+
pass
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
class ActionIndeterminate(ActionError):
|
|
309
|
+
pass
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
class ActionConflict(ActionError):
|
|
313
|
+
def __init__(self, code: str, retained: bool, original: OutcomeDetails):
|
|
314
|
+
self.retained = retained
|
|
315
|
+
super().__init__(code, original)
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
class ActionFailed(ActionError):
|
|
319
|
+
def __init__(
|
|
320
|
+
self, code: str, cause: BaseException, original: OutcomeDetails | None = None
|
|
321
|
+
):
|
|
322
|
+
self.cause = cause
|
|
323
|
+
super().__init__(code, original)
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
class ActionRejected(ActionError):
|
|
327
|
+
def __init__(
|
|
328
|
+
self, code: str, retryable: bool, original: OutcomeDetails | None = None
|
|
329
|
+
):
|
|
330
|
+
self.retryable = retryable
|
|
331
|
+
super().__init__(code, original)
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def _timeout(value: timedelta | None) -> None:
|
|
335
|
+
if value is None:
|
|
336
|
+
return # Executor is required to apply its finite configured default.
|
|
337
|
+
if (
|
|
338
|
+
type(value) is not timedelta
|
|
339
|
+
or not isfinite(value.total_seconds())
|
|
340
|
+
or value.total_seconds() < 0
|
|
341
|
+
):
|
|
342
|
+
raise ActionRefused("TIMEOUT")
|
|
343
|
+
if value.total_seconds() == 0:
|
|
344
|
+
raise ActionRefused("DEADLINE_EXPIRED")
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def _input(
|
|
348
|
+
action: ActionRef[InputT, OutputT], value: InputT, timeout: timedelta | None
|
|
349
|
+
) -> dict[str, object]:
|
|
350
|
+
_timeout(timeout)
|
|
351
|
+
if action.source is None:
|
|
352
|
+
raise ActionRefused("ACTION_SOURCE_REQUIRED")
|
|
353
|
+
checked = revalidate_model(action.input_type, value)
|
|
354
|
+
# Local ABI carriers, not an invented engine/native wire encoding. Adapters
|
|
355
|
+
# own profile-specific transport, including exact Key/source correspondence.
|
|
356
|
+
return {name: item for name, item in checked if item is not MISSING}
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def _project(
|
|
360
|
+
action: ActionRef[InputT, OutputT],
|
|
361
|
+
outcome: ActionOutcome,
|
|
362
|
+
rejection: type[ActionRejected],
|
|
363
|
+
) -> Committed[OutputT]:
|
|
364
|
+
if isinstance(outcome, Replayed):
|
|
365
|
+
outcome = outcome.outcome
|
|
366
|
+
if outcome.original.action != action:
|
|
367
|
+
raise ActionIndeterminate("ORIGINAL_ACTION_MISMATCH", outcome.original)
|
|
368
|
+
if isinstance(outcome, Committed):
|
|
369
|
+
if action.output_type is type(None):
|
|
370
|
+
if outcome.output is not None:
|
|
371
|
+
raise ActionIndeterminate("OUTPUT_TYPE", outcome.original)
|
|
372
|
+
elif isinstance(action.output_type, type) and issubclass(
|
|
373
|
+
action.output_type, StrictModel
|
|
374
|
+
):
|
|
375
|
+
try:
|
|
376
|
+
checked = revalidate_model(
|
|
377
|
+
action.output_type, cast(StrictModel, outcome.output)
|
|
378
|
+
)
|
|
379
|
+
except (TypeError, ValueError) as error:
|
|
380
|
+
raise ActionIndeterminate("OUTPUT_TYPE", outcome.original) from error
|
|
381
|
+
outcome = Committed(
|
|
382
|
+
checked,
|
|
383
|
+
outcome.receipt,
|
|
384
|
+
outcome.created,
|
|
385
|
+
outcome.changed,
|
|
386
|
+
outcome.original,
|
|
387
|
+
)
|
|
388
|
+
else:
|
|
389
|
+
raise ActionIndeterminate("OUTPUT_TYPE", outcome.original)
|
|
390
|
+
return cast(Committed[OutputT], outcome)
|
|
391
|
+
if isinstance(outcome, Rejected):
|
|
392
|
+
raise rejection(
|
|
393
|
+
code=outcome.code, retryable=outcome.retryable, original=outcome.original
|
|
394
|
+
)
|
|
395
|
+
if isinstance(outcome, Denied):
|
|
396
|
+
raise ActionDenied(outcome.code, outcome.original)
|
|
397
|
+
if isinstance(outcome, Conflict):
|
|
398
|
+
raise ActionConflict(outcome.code, outcome.retained, outcome.original)
|
|
399
|
+
if isinstance(outcome, TimedOut):
|
|
400
|
+
raise ActionTimedOut("TIMED_OUT", outcome.original)
|
|
401
|
+
if isinstance(outcome, Indeterminate):
|
|
402
|
+
raise ActionIndeterminate("INDETERMINATE", outcome.original)
|
|
403
|
+
raise TypeError("unknown action outcome")
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def make_committed_view(
|
|
407
|
+
action: ActionRef[Any, Any], outcome: Committed[Any], result_type: type[C] | None
|
|
408
|
+
) -> C:
|
|
409
|
+
if result_type is None:
|
|
410
|
+
return cast(C, outcome)
|
|
411
|
+
if getattr(result_type, "UMF_BUNDLE_INPUT_DIGEST", None) != getattr(
|
|
412
|
+
action.input_type, "UMF_BUNDLE_INPUT_DIGEST", None
|
|
413
|
+
):
|
|
414
|
+
raise ActionIndeterminate("RESULT_VIEW_SOURCE", outcome.original)
|
|
415
|
+
checked = []
|
|
416
|
+
for name, allowed_name in (
|
|
417
|
+
("created", "CREATED_KEY_TYPES"),
|
|
418
|
+
("changed", "CHANGED_KEY_TYPES"),
|
|
419
|
+
):
|
|
420
|
+
values = getattr(outcome, name)
|
|
421
|
+
allowed = getattr(result_type, allowed_name, None)
|
|
422
|
+
if type(values) is not tuple or type(allowed) is not tuple:
|
|
423
|
+
raise ActionIndeterminate("RESULT_KEY_INVENTORY", outcome.original)
|
|
424
|
+
keys = []
|
|
425
|
+
for value in values:
|
|
426
|
+
if type(value) not in allowed or not any(
|
|
427
|
+
type(value) is reference.model for reference in action.key_types
|
|
428
|
+
):
|
|
429
|
+
raise ActionIndeterminate("RESULT_KEY_TYPE", outcome.original)
|
|
430
|
+
if getattr(type(value), "UMF_BUNDLE_INPUT_DIGEST", None) != getattr(
|
|
431
|
+
action.input_type, "UMF_BUNDLE_INPUT_DIGEST", None
|
|
432
|
+
):
|
|
433
|
+
raise ActionIndeterminate("RESULT_KEY_SOURCE", outcome.original)
|
|
434
|
+
try:
|
|
435
|
+
keys.append(revalidate_model(type(value), value))
|
|
436
|
+
except (TypeError, ValueError) as error:
|
|
437
|
+
raise ActionIndeterminate(
|
|
438
|
+
"RESULT_KEY_VALUE", outcome.original
|
|
439
|
+
) from error
|
|
440
|
+
checked.append(tuple(keys))
|
|
441
|
+
return result_type(
|
|
442
|
+
outcome.output, outcome.receipt, checked[0], checked[1], outcome.original
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
async def _await_project(
|
|
447
|
+
action: ActionRef[InputT, Any],
|
|
448
|
+
outcome: Awaitable[ActionOutcome],
|
|
449
|
+
rejection: type[ActionRejected],
|
|
450
|
+
result_type: type[C] | None,
|
|
451
|
+
) -> C:
|
|
452
|
+
# Cancellation/settlement belong to the original executor, never a new call.
|
|
453
|
+
return make_committed_view(
|
|
454
|
+
action, _project(action, await outcome, rejection), result_type
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
def _dispatch(
|
|
459
|
+
action: ActionRef[InputT, Any],
|
|
460
|
+
answer: ActionOutcome | Awaitable[ActionOutcome],
|
|
461
|
+
rejection: type[ActionRejected],
|
|
462
|
+
result_type: type[C] | None,
|
|
463
|
+
) -> C | Awaitable[C]:
|
|
464
|
+
if isinstance(answer, Awaitable):
|
|
465
|
+
return _await_project(action, answer, rejection, result_type)
|
|
466
|
+
return make_committed_view(action, _project(action, answer, rejection), result_type)
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
class ActionEndpoint(Generic[InputT, C, ExecutorT]):
|
|
470
|
+
def __init__(
|
|
471
|
+
self,
|
|
472
|
+
executor: ExecutorT,
|
|
473
|
+
action: ActionRef[InputT, Any],
|
|
474
|
+
rejection: type[ActionRejected] = ActionRejected,
|
|
475
|
+
result_type: type[C] | None = None,
|
|
476
|
+
):
|
|
477
|
+
if not isinstance(executor, (ActionExecutor, AsyncActionExecutor)):
|
|
478
|
+
raise TypeError("ActionExecutor required")
|
|
479
|
+
self.executor, self.action, self.rejection, self.result_type = (
|
|
480
|
+
executor,
|
|
481
|
+
action,
|
|
482
|
+
rejection,
|
|
483
|
+
result_type,
|
|
484
|
+
)
|
|
485
|
+
|
|
486
|
+
@overload
|
|
487
|
+
def __call__(
|
|
488
|
+
self: ActionEndpoint[InputT, C, ActionExecutor],
|
|
489
|
+
input: InputT,
|
|
490
|
+
*,
|
|
491
|
+
timeout: timedelta | None = None,
|
|
492
|
+
) -> C: ...
|
|
493
|
+
@overload
|
|
494
|
+
def __call__(
|
|
495
|
+
self: ActionEndpoint[InputT, C, AsyncActionExecutor],
|
|
496
|
+
input: InputT,
|
|
497
|
+
*,
|
|
498
|
+
timeout: timedelta | None = None,
|
|
499
|
+
) -> Awaitable[C]: ...
|
|
500
|
+
def __call__(
|
|
501
|
+
self, input: InputT, *, timeout: timedelta | None = None
|
|
502
|
+
) -> C | Awaitable[C]:
|
|
503
|
+
return _dispatch(
|
|
504
|
+
self.action,
|
|
505
|
+
self.executor.invoke(
|
|
506
|
+
self.action, _input(self.action, input, timeout), timeout=timeout
|
|
507
|
+
),
|
|
508
|
+
self.rejection,
|
|
509
|
+
self.result_type,
|
|
510
|
+
)
|
|
511
|
+
|
|
512
|
+
@overload
|
|
513
|
+
def validate(
|
|
514
|
+
self: ActionEndpoint[InputT, C, ActionExecutor],
|
|
515
|
+
input: InputT,
|
|
516
|
+
*,
|
|
517
|
+
timeout: timedelta | None = None,
|
|
518
|
+
) -> ValidationResult: ...
|
|
519
|
+
@overload
|
|
520
|
+
def validate(
|
|
521
|
+
self: ActionEndpoint[InputT, C, AsyncActionExecutor],
|
|
522
|
+
input: InputT,
|
|
523
|
+
*,
|
|
524
|
+
timeout: timedelta | None = None,
|
|
525
|
+
) -> Awaitable[ValidationResult]: ...
|
|
526
|
+
def validate(
|
|
527
|
+
self, input: InputT, *, timeout: timedelta | None = None
|
|
528
|
+
) -> ValidationResult | Awaitable[ValidationResult]:
|
|
529
|
+
return self.executor.validate(
|
|
530
|
+
self.action, _input(self.action, input, timeout), timeout=timeout
|
|
531
|
+
)
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
class ReplayingActionEndpoint(Generic[InputT, C, ReplayingExecutorT]):
|
|
535
|
+
def __init__(
|
|
536
|
+
self,
|
|
537
|
+
executor: ReplayingExecutorT,
|
|
538
|
+
action: ActionRef[InputT, Any],
|
|
539
|
+
rejection: type[ActionRejected] = ActionRejected,
|
|
540
|
+
result_type: type[C] | None = None,
|
|
541
|
+
):
|
|
542
|
+
if not isinstance(
|
|
543
|
+
executor, (ReplayingActionExecutor, AsyncReplayingActionExecutor)
|
|
544
|
+
):
|
|
545
|
+
raise TypeError("ReplayingActionExecutor required")
|
|
546
|
+
self.executor, self.action, self.rejection, self.result_type = (
|
|
547
|
+
executor,
|
|
548
|
+
action,
|
|
549
|
+
rejection,
|
|
550
|
+
result_type,
|
|
551
|
+
)
|
|
552
|
+
|
|
553
|
+
@overload
|
|
554
|
+
def __call__(
|
|
555
|
+
self: ReplayingActionEndpoint[InputT, C, ReplayingActionExecutor],
|
|
556
|
+
input: InputT,
|
|
557
|
+
*,
|
|
558
|
+
idempotency_key: str,
|
|
559
|
+
timeout: timedelta | None = None,
|
|
560
|
+
) -> C: ...
|
|
561
|
+
@overload
|
|
562
|
+
def __call__(
|
|
563
|
+
self: ReplayingActionEndpoint[InputT, C, AsyncReplayingActionExecutor],
|
|
564
|
+
input: InputT,
|
|
565
|
+
*,
|
|
566
|
+
idempotency_key: str,
|
|
567
|
+
timeout: timedelta | None = None,
|
|
568
|
+
) -> Awaitable[C]: ...
|
|
569
|
+
def __call__(
|
|
570
|
+
self, input: InputT, *, idempotency_key: str, timeout: timedelta | None = None
|
|
571
|
+
) -> C | Awaitable[C]:
|
|
572
|
+
if type(idempotency_key) is not str or not idempotency_key:
|
|
573
|
+
raise ActionRefused("IDEMPOTENCY_KEY")
|
|
574
|
+
return _dispatch(
|
|
575
|
+
self.action,
|
|
576
|
+
self.executor.invoke_keyed(
|
|
577
|
+
self.action,
|
|
578
|
+
_input(self.action, input, timeout),
|
|
579
|
+
idempotency_key=idempotency_key,
|
|
580
|
+
timeout=timeout,
|
|
581
|
+
),
|
|
582
|
+
self.rejection,
|
|
583
|
+
self.result_type,
|
|
584
|
+
)
|
|
585
|
+
|
|
586
|
+
@overload
|
|
587
|
+
def validate(
|
|
588
|
+
self: ReplayingActionEndpoint[InputT, C, ReplayingActionExecutor],
|
|
589
|
+
input: InputT,
|
|
590
|
+
*,
|
|
591
|
+
timeout: timedelta | None = None,
|
|
592
|
+
) -> ValidationResult: ...
|
|
593
|
+
@overload
|
|
594
|
+
def validate(
|
|
595
|
+
self: ReplayingActionEndpoint[InputT, C, AsyncReplayingActionExecutor],
|
|
596
|
+
input: InputT,
|
|
597
|
+
*,
|
|
598
|
+
timeout: timedelta | None = None,
|
|
599
|
+
) -> Awaitable[ValidationResult]: ...
|
|
600
|
+
def validate(
|
|
601
|
+
self, input: InputT, *, timeout: timedelta | None = None
|
|
602
|
+
) -> ValidationResult | Awaitable[ValidationResult]:
|
|
603
|
+
return self.executor.validate(
|
|
604
|
+
self.action, _input(self.action, input, timeout), timeout=timeout
|
|
605
|
+
)
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
ReadP = TypeVar("ReadP", bound=BaseModel)
|
|
609
|
+
ReadR = TypeVar("ReadR", bound=BaseModel)
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
class ReadTarget(Protocol):
|
|
613
|
+
def identity(self) -> TargetIdentity: ...
|
|
614
|
+
def read(
|
|
615
|
+
self,
|
|
616
|
+
entry: CatalogRead[ReadP, ReadR],
|
|
617
|
+
parameters: ReadP,
|
|
618
|
+
*,
|
|
619
|
+
timeout: timedelta | None = None,
|
|
620
|
+
) -> list[ReadR]: ...
|
|
621
|
+
def page(
|
|
622
|
+
self,
|
|
623
|
+
entry: CatalogRead[ReadP, ReadR],
|
|
624
|
+
parameters: ReadP,
|
|
625
|
+
*,
|
|
626
|
+
after: ReadContinuation | None = None,
|
|
627
|
+
timeout: timedelta | None = None,
|
|
628
|
+
) -> ReadPage[ReadR]: ...
|
|
629
|
+
def stream(
|
|
630
|
+
self,
|
|
631
|
+
entry: CatalogRead[ReadP, ReadR],
|
|
632
|
+
parameters: ReadP,
|
|
633
|
+
*,
|
|
634
|
+
max_rows: int,
|
|
635
|
+
page_size: int | None = None,
|
|
636
|
+
timeout: timedelta | None = None,
|
|
637
|
+
) -> Generator[ReadR, None, None]: ...
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
class AsyncReadTarget(Protocol):
|
|
641
|
+
def identity(self) -> TargetIdentity: ...
|
|
642
|
+
async def read(
|
|
643
|
+
self,
|
|
644
|
+
entry: CatalogRead[ReadP, ReadR],
|
|
645
|
+
parameters: ReadP,
|
|
646
|
+
*,
|
|
647
|
+
timeout: timedelta | None = None,
|
|
648
|
+
) -> list[ReadR]: ...
|
|
649
|
+
async def page(
|
|
650
|
+
self,
|
|
651
|
+
entry: CatalogRead[ReadP, ReadR],
|
|
652
|
+
parameters: ReadP,
|
|
653
|
+
*,
|
|
654
|
+
after: ReadContinuation | None = None,
|
|
655
|
+
timeout: timedelta | None = None,
|
|
656
|
+
) -> ReadPage[ReadR]: ...
|
|
657
|
+
def stream(
|
|
658
|
+
self,
|
|
659
|
+
entry: CatalogRead[ReadP, ReadR],
|
|
660
|
+
parameters: ReadP,
|
|
661
|
+
*,
|
|
662
|
+
max_rows: int,
|
|
663
|
+
page_size: int | None = None,
|
|
664
|
+
timeout: timedelta | None = None,
|
|
665
|
+
) -> AsyncGenerator[ReadR, None]: ...
|
umf_access/py.typed
ADDED
|
File without changes
|