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.
Files changed (117) hide show
  1. umf_access/__init__.py +109 -0
  2. umf_access/adoption.py +41 -0
  3. umf_access/build/__init__.py +2 -0
  4. umf_access/build/approximate.py +34 -0
  5. umf_access/build/catalog.py +1626 -0
  6. umf_access/build/commands.py +394 -0
  7. umf_access/build/pg_privileges.py +1544 -0
  8. umf_access/build/privileges.py +134 -0
  9. umf_access/build/search.py +365 -0
  10. umf_access/build/unity_search.py +104 -0
  11. umf_access/bulk.py +227 -0
  12. umf_access/canonical.py +23 -0
  13. umf_access/capture.py +410 -0
  14. umf_access/catalog.py +325 -0
  15. umf_access/codec_support.py +427 -0
  16. umf_access/commands.py +93 -0
  17. umf_access/delta_read.py +758 -0
  18. umf_access/dsl/__init__.py +148 -0
  19. umf_access/dsl/_context.py +36 -0
  20. umf_access/dsl/_expressions.py +625 -0
  21. umf_access/dsl/_joined.py +4 -0
  22. umf_access/dsl/_nodes.py +207 -0
  23. umf_access/dsl/_query.py +5559 -0
  24. umf_access/dsl/_selection.py +143 -0
  25. umf_access/dsl/navigation.py +302 -0
  26. umf_access/dsl/render.py +516 -0
  27. umf_access/dsl/search.py +343 -0
  28. umf_access/engine_catalog.py +563 -0
  29. umf_access/generated_core.py +5 -0
  30. umf_access/lifecycle/__init__.py +46 -0
  31. umf_access/lifecycle/_darwin_process_observer.c +306 -0
  32. umf_access/lifecycle/approval.py +366 -0
  33. umf_access/lifecycle/backfills.py +79 -0
  34. umf_access/lifecycle/catalog.py +289 -0
  35. umf_access/lifecycle/cli.py +231 -0
  36. umf_access/lifecycle/concurrent.py +196 -0
  37. umf_access/lifecycle/conversion_policy.py +188 -0
  38. umf_access/lifecycle/correspondence.py +203 -0
  39. umf_access/lifecycle/generation_authority_bootstrap.py +1491 -0
  40. umf_access/lifecycle/generation_authority_session.py +125 -0
  41. umf_access/lifecycle/generation_enrollment_authority.py +1108 -0
  42. umf_access/lifecycle/generation_enrollment_ledger.py +698 -0
  43. umf_access/lifecycle/generation_ingress.py +185 -0
  44. umf_access/lifecycle/generation_root_registry.py +138 -0
  45. umf_access/lifecycle/head.py +250 -0
  46. umf_access/lifecycle/head_view.py +81 -0
  47. umf_access/lifecycle/host.py +1183 -0
  48. umf_access/lifecycle/ingress_custody.py +750 -0
  49. umf_access/lifecycle/ingress_local_postgres.py +7990 -0
  50. umf_access/lifecycle/ingress_store.py +1488 -0
  51. umf_access/lifecycle/ledger.py +276 -0
  52. umf_access/lifecycle/ledger_schema.py +116 -0
  53. umf_access/lifecycle/mixed.py +593 -0
  54. umf_access/lifecycle/outcome_schema.py +136 -0
  55. umf_access/lifecycle/owner_approval_core.py +1810 -0
  56. umf_access/lifecycle/owner_authority.py +472 -0
  57. umf_access/lifecycle/owner_bootstrap.py +2077 -0
  58. umf_access/lifecycle/owner_wire.py +161 -0
  59. umf_access/lifecycle/phase_fence.py +52 -0
  60. umf_access/lifecycle/phase_policy.py +422 -0
  61. umf_access/lifecycle/privileges.py +145 -0
  62. umf_access/lifecycle/probe.py +39 -0
  63. umf_access/lifecycle/progress.py +497 -0
  64. umf_access/lifecycle/roles.py +96 -0
  65. umf_access/lifecycle/row_originals.py +1712 -0
  66. umf_access/lifecycle/row_originals_creation.py +759 -0
  67. umf_access/lifecycle/row_originals_receipt.py +413 -0
  68. umf_access/lifecycle/seeds.py +99 -0
  69. umf_access/lifecycle/sql_containment.py +358 -0
  70. umf_access/lifecycle/sql_containment_cli.py +33 -0
  71. umf_access/lifecycle/sql_containment_parser.py +20 -0
  72. umf_access/lifecycle/supervisor_journal_codec.py +1251 -0
  73. umf_access/lifecycle/table_boundary.py +22 -0
  74. umf_access/lifecycle/target_custody_codec.py +788 -0
  75. umf_access/lifecycle/witness.py +72 -0
  76. umf_access/managed_actions.py +271 -0
  77. umf_access/managed_bulk.py +353 -0
  78. umf_access/managed_delta.py +150 -0
  79. umf_access/managed_support.py +166 -0
  80. umf_access/manifest_commands.py +278 -0
  81. umf_access/native_actions.py +1007 -0
  82. umf_access/native_program.py +570 -0
  83. umf_access/pages.py +125 -0
  84. umf_access/postgres_bulk.py +509 -0
  85. umf_access/postgres_read.py +1230 -0
  86. umf_access/postgres_search.py +639 -0
  87. umf_access/protocols.py +665 -0
  88. umf_access/py.typed +0 -0
  89. umf_access/related_keys.py +233 -0
  90. umf_access/reviewed.py +706 -0
  91. umf_access/search_catalog.py +122 -0
  92. umf_access/targets.py +312 -0
  93. umf_access/types.py +220 -0
  94. umf_access/unified/__init__.py +187 -0
  95. umf_access/unified/_binding.py +654 -0
  96. umf_access/unified/head_session.py +144 -0
  97. umf_access/unified/native_binding.py +143 -0
  98. umf_access/unified/operation_values.py +173 -0
  99. umf_access/unified/outcome_values.py +76 -0
  100. umf_access/unified/session_async.py +161 -0
  101. umf_access/unified/session_binding.py +108 -0
  102. umf_access/unified/session_policy.py +152 -0
  103. umf_access/unified/session_psycopg2.py +70 -0
  104. umf_access/unified/session_sqlalchemy.py +161 -0
  105. umf_access/unified/session_sync.py +148 -0
  106. umf_access/unified/table_reads.py +314 -0
  107. umf_access/unified/table_writes.py +193 -0
  108. umf_access/unity_search.py +312 -0
  109. umf_access/values.py +280 -0
  110. umf_access/verification.py +64 -0
  111. umf_access-0.1.0.dev8.dist-info/METADATA +15 -0
  112. umf_access-0.1.0.dev8.dist-info/RECORD +117 -0
  113. umf_access-0.1.0.dev8.dist-info/WHEEL +4 -0
  114. umf_access-0.1.0.dev8.dist-info/entry_points.txt +4 -0
  115. umf_access-0.1.0.dev8.dist-info/licenses/LICENSE-APACHE +201 -0
  116. umf_access-0.1.0.dev8.dist-info/licenses/LICENSE-MIT +21 -0
  117. umf_access-0.1.0.dev8.dist-info/licenses/LICENSE.md +239 -0
@@ -0,0 +1,563 @@
1
+ # SPDX-License-Identifier: MIT OR Apache-2.0
2
+ """Inert engine catalogs; native admission and compilation equality stay owned.
3
+
4
+ A valid wrapper conveys source/type custody only. It never grants read or action
5
+ permission, selects an engine connection, or interprets engine storage SQL.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import hashlib
11
+ from collections.abc import Mapping
12
+ from dataclasses import dataclass
13
+ from types import UnionType
14
+ from typing import Annotated, Any, TypeVar, Union, get_args, get_origin
15
+
16
+ from pydantic import BaseModel
17
+
18
+ from .generated_core import CURRENT_CORE_VERSION
19
+ from .native_program import ProgramBuildError, canonical_json, program_json
20
+ from .related_keys import transport_spec
21
+ from .reviewed import (
22
+ CatalogRead,
23
+ ReadBuildError,
24
+ _carrier,
25
+ _compatible_outputs,
26
+ _fields,
27
+ _generation,
28
+ )
29
+ from .types import MISSING
30
+
31
+ P = TypeVar("P", bound=BaseModel)
32
+ R = TypeVar("R", bound=BaseModel)
33
+
34
+
35
+ def _engine_scalar_signature(annotation: object, *, allow_binary: bool = False) -> dict[str, object]:
36
+ """Keep absent and explicit null separate, including nested Annotated unions."""
37
+ def members(value: object, depth: int = 0) -> list[object]:
38
+ if depth > 32:
39
+ raise ReadBuildError('bounded engine annotation required')
40
+ origin = get_origin(value)
41
+ if origin is Annotated:
42
+ return members(get_args(value)[0], depth + 1)
43
+ if origin in (Union, UnionType):
44
+ result = []
45
+ for item in get_args(value):
46
+ result.extend(members(item, depth + 1))
47
+ return result
48
+ return [value]
49
+ variants = members(annotation)
50
+ present = [value for value in variants if value is not MISSING and value is not type(None)]
51
+ if len(present) != 1:
52
+ raise ReadBuildError('one exact engine scalar carrier required')
53
+ if allow_binary and present[0] is bytes:
54
+ return {'carrier': 'binary', 'nullable': type(None) in variants,
55
+ 'missing': any(value is MISSING for value in variants)}
56
+ carrier, nullable = _carrier(present[0])
57
+ if nullable or carrier not in ('string', 'integer', 'decimal', 'boolean'):
58
+ raise ReadBuildError('original engine scalar profile required')
59
+ return {'carrier': carrier, 'nullable': type(None) in variants,
60
+ 'missing': any(value is MISSING for value in variants)}
61
+
62
+
63
+ def _engine_fields(model: type[BaseModel], *, allow_binary: bool = False) -> list[dict[str, object]]:
64
+ """Engine output-only signature; original raw/parameter paths unchanged."""
65
+ if model.model_config.get('extra') != 'forbid' or model.model_config.get('strict') is not True:
66
+ raise ReadBuildError('strict engine output model required')
67
+ related = transport_spec(model)
68
+ result = []
69
+ for name, field in model.model_fields.items():
70
+ if field.alias is not None:
71
+ raise ReadBuildError('engine output aliases are unsupported')
72
+ if related is not None and name == related[0]:
73
+ # A generated sealed transport owns this exact decoder/class pair.
74
+ result.append({'name': name, 'carrier': 'related-keys', 'nullable': False,
75
+ 'missing': False, 'decoder': related[2]})
76
+ else:
77
+ result.append({'name': name, **_engine_scalar_signature(field.annotation, allow_binary=allow_binary)})
78
+ return result
79
+
80
+
81
+
82
+
83
+ def _engine_output_custody(program: Mapping[str, Any], expected: list[dict[str, object]]) -> None:
84
+ """Match original direct-Field presence to its original graph and columns.
85
+
86
+ Native value decoding and integrity remain owned by the engine. A physical
87
+ envelope column's nullability is not the logical Field null domain.
88
+ """
89
+ actual = program.get("outputs")
90
+ artifact = program.get("artifact")
91
+ if type(actual) is not list or len(actual) != len(expected) or type(artifact) is not dict:
92
+ raise ReadBuildError("original engine output inventory required")
93
+ columns, pins = artifact.get("columns"), artifact.get("modelPins")
94
+ plan = artifact.get("logicalPlan")
95
+ if type(columns) is not list or type(pins) is not list or not pins or type(plan) is not dict:
96
+ raise ReadBuildError("original engine column/model custody required")
97
+ ordered = program.get("version") == "weft.engine-page/0.2"
98
+ if ordered:
99
+ page = program.get("page")
100
+ if (type(page) is not dict or page.get("visibleOutputs") != len(actual)
101
+ or page.get("selectedKey") != program.get("selectedKey")
102
+ or plan.get("selectedKey") != page.get("key")
103
+ or plan.get("keySlots") != page.get("keySlots")):
104
+ raise ReadBuildError("original ordered page correspondence differs")
105
+ selected = _selected_key(program.get("selectedKey"))
106
+ if type(page.get("key")) is not dict or type(page["key"].get("fields")) is not list:
107
+ raise ReadBuildError("original ordered Key inventory required")
108
+ if page["key"].get("id") != selected["key"]:
109
+ raise ReadBuildError("original ordered selected Key differs")
110
+ source_slots, slots = plan.get("sortSlots"), page.get("sortSlots")
111
+ if type(source_slots) is not list or type(slots) is not list or len(source_slots) != len(slots):
112
+ raise ReadBuildError("original ordered slot inventory differs")
113
+ for original_slot, slot in zip(source_slots, slots, strict=True):
114
+ if (type(original_slot) is not dict or type(slot) is not dict
115
+ or any(type(original_slot.get(k)) is not bool for k in ("descending", "nullsFirst", "nullable", "missing"))
116
+ or any(type(original_slot.get(k)) is not int for k in ("stateOutput", "valueOutput"))
117
+ or type(original_slot.get("logicalType")) is not dict):
118
+ raise ReadBuildError("closed original ordered slot required")
119
+ logical = original_slot["logicalType"]
120
+ if slot != {"carrier": logical.get("family"), "facets": logical.get("facets"),
121
+ "field": original_slot.get("identity"), "direction": "desc" if original_slot.get("descending") else "asc",
122
+ "nulls": "first" if original_slot.get("nullsFirst") else "last",
123
+ **{k: original_slot.get(k) for k in ("nullable", "missing", "stateOutput", "valueOutput")}}:
124
+ raise ReadBuildError("original ordered slot correspondence differs")
125
+ indices = page.get("keySlots")
126
+ if (type(indices) is not list or len(indices) != len(page["key"].get("fields", []))
127
+ or any(type(i) is not int or not 0 <= i < len(slots) for i in indices)
128
+ or [slots[i]["field"] for i in indices] != page["key"]["fields"]
129
+ or page.get("keyOutputs") != [slots[i]["valueOutput"] for i in indices]):
130
+ raise ReadBuildError("original ordered Key slot mapping differs")
131
+ plan = plan.get("base")
132
+ if type(plan) is not dict:
133
+ raise ReadBuildError("original ordered base plan required")
134
+ if "orderKey" in program:
135
+ order_key = _selected_key(program["orderKey"])
136
+ read_order = plan.get("readOrder")
137
+ record = plan.get("source", {}).get("record", {})
138
+ if (type(read_order) is not dict or type(read_order.get("selectedKey")) is not dict
139
+ or read_order["selectedKey"].get("id") != order_key["key"]
140
+ or record.get("module") != order_key["module"] or record.get("element") != order_key["record"]):
141
+ raise ReadBuildError("original ordered read Key correspondence differs")
142
+ if "relatedRequest" in program:
143
+ navigation = plan.get("navigation")
144
+ source_key = program["relatedRequest"].get("sourceSelectedKey")
145
+ if (type(navigation) is not dict or navigation.get("sourceSelectedKey") != source_key):
146
+ raise ReadBuildError("original navigation source Key differs")
147
+ graph, projections = plan.get("typeGraph"), plan.get("outputs")
148
+ if type(graph) is not list or type(projections) is not list or len(projections) != len(actual):
149
+ raise ReadBuildError("original engine projection/type graph required")
150
+ request = program.get("request")
151
+ if type(request) is not dict:
152
+ raise ReadBuildError("original engine request required")
153
+ modules = request.get("modules")
154
+ if type(modules) is not list:
155
+ raise ReadBuildError("original engine module source required")
156
+ for output, wanted, projection in zip(actual, expected, projections, strict=True):
157
+ if type(output) is not dict or output.get("name") != wanted["name"]:
158
+ raise ReadBuildError("engine output name differs from declared model")
159
+ if wanted.get("carrier") == "related-keys":
160
+ if output != wanted:
161
+ raise ReadBuildError("original related-Key transport differs")
162
+ decoder = wanted["decoder"]
163
+ native = [c for c in columns if type(c) is dict and c.get("outputName") == output["name"]]
164
+ expression = projection.get("expression") if type(projection) is dict else None
165
+ relationship = expression.get("relationship") if type(expression) is dict else None
166
+ if (type(decoder) is not dict or len(native) != 1
167
+ or decoder.get("modelPins") != pins
168
+ or native[0].get("representation") != decoder.get("representation")
169
+ or type(expression) is not dict or expression.get("op") != "relatedKeys"
170
+ or expression.get("bound") != decoder.get("bound")
171
+ or type(relationship) is not dict):
172
+ raise ReadBuildError("original related-Key column/projection differs")
173
+ representation = decoder["representation"]
174
+ inverse = decoder["relationship"]["direction"] == "inverse"
175
+ if (relationship.get("identity") != representation["relationship"]
176
+ or relationship.get("inverse") is not inverse
177
+ or relationship.get("sourceKey" if inverse else "targetKey") != representation["key"]
178
+ or relationship.get("from" if inverse else "to") != decoder["target"]):
179
+ raise ReadBuildError("original related-Key identity/Key differs")
180
+ continue
181
+ if set(output) != {"name", "carrier", "nullable", "missing", "source", "representation", "modelPins"}:
182
+ raise ReadBuildError("closed original engine direct-Field output required")
183
+ if (type(output["nullable"]) is not bool or type(output["missing"]) is not bool
184
+ or output["carrier"] != wanted["carrier"]
185
+ or output["nullable"] and not wanted["nullable"]
186
+ or output["missing"] and not wanted["missing"]):
187
+ raise ReadBuildError("engine output presence or carrier narrows the original Field")
188
+ source = output["source"]
189
+ if (type(source) is not dict or set(source) != {"documentId", "revision", "module", "element"}
190
+ or any(type(v) is not str or not v for v in source.values())
191
+ or output["modelPins"] != pins):
192
+ raise ReadBuildError("original engine Field/model pins differ")
193
+ native = [c for c in columns if type(c) is dict and c.get("outputName") == output["name"]]
194
+ types = [t for t in graph if type(t) is dict and t.get("identity") == source]
195
+ if (len(native) != 1 or len(types) != 1
196
+ or native[0].get("sourceIdentities") != [source]
197
+ or native[0].get("representation") != output["representation"]
198
+ or type(projection) is not dict or projection.get("name") != output["name"]
199
+ or type(projection.get("expression")) is not dict
200
+ or projection["expression"].get("op") != "field"
201
+ or projection["expression"].get("identity") != source):
202
+ raise ReadBuildError("original engine projection/column/source correspondence differs")
203
+ typed = types[0]
204
+ logical = typed.get("type")
205
+ representation = output["representation"]
206
+ if (typed.get("kind") != "scalar" or typed.get("availability") not in ("required", "absent-allowed")
207
+ or type(logical) is not dict or logical.get("family") != output["carrier"]
208
+ or type(logical.get("nullable")) is not bool or logical["nullable"] != output["nullable"]
209
+ or output["missing"] != (typed["availability"] == "absent-allowed")
210
+ or type(representation) is not dict or representation.get("kind") != "value"
211
+ or representation.get("descriptor") != source or representation.get("nativeNull") is not True):
212
+ raise ReadBuildError("original engine logical Field presence differs")
213
+ matching_pins = [pin for pin in pins if type(pin) is dict
214
+ and pin.get("documentId") == source["documentId"] and pin.get("revision") == source["revision"]]
215
+ documents = [m for m in modules if type(m) is dict and m.get("pin") in matching_pins
216
+ and type(m.get("selectedModuleIds")) is list and source["module"] in m["selectedModuleIds"]]
217
+ if len(matching_pins) != 1 or len(documents) != 1 or type(documents[0].get("documentJson")) is not str:
218
+ raise ReadBuildError("original engine selected module pin differs")
219
+ text = documents[0]["documentJson"]
220
+ if hashlib.sha256(text.encode()).hexdigest() != matching_pins[0].get("sha256"):
221
+ raise ReadBuildError("original engine document bytes differ from pin")
222
+ document = program_json(text)
223
+ if document.get("id") != source["documentId"] or document.get("umf") != matching_pins[0].get("umfVersion"):
224
+ raise ReadBuildError("original engine document identity differs")
225
+
226
+
227
+ def _truss_field_source(source: object, pins: list[Any], program: Mapping[str, Any]) -> None:
228
+ if (type(source) is not dict or set(source) != {"documentId", "revision", "module", "element"}
229
+ or any(type(v) is not str or not v for v in source.values())):
230
+ raise ReadBuildError("original Truss Field source required")
231
+ request = program.get("request")
232
+ if type(request) is not dict or type(request.get("modules")) is not list:
233
+ raise ReadBuildError("original Truss modules required")
234
+ matched = [pin for pin in pins if type(pin) is dict and pin.get("documentId") == source["documentId"] and pin.get("revision") == source["revision"]]
235
+ documents = [m for m in request["modules"] if type(m) is dict and m.get("pin") in matched and type(m.get("selectedModuleIds")) is list and source["module"] in m["selectedModuleIds"]]
236
+ if (len(matched) != 1 or matched[0].get("umfVersion") != CURRENT_CORE_VERSION or len(documents) != 1
237
+ or type(documents[0].get("documentJson")) is not str
238
+ or hashlib.sha256(documents[0]["documentJson"].encode()).hexdigest() != matched[0].get("sha256")):
239
+ raise ReadBuildError("original current-core Truss document pin differs")
240
+ document = program_json(documents[0]["documentJson"])
241
+ if type(document) is not dict or document.get("id") != source["documentId"] or document.get("umf") != CURRENT_CORE_VERSION:
242
+ raise ReadBuildError("original current-core Truss document identity differs")
243
+
244
+
245
+ def _truss_binary_output_custody(program: Mapping[str, Any], expected: list[dict[str, object]]) -> None:
246
+ """Retain original Truss binary/state metadata; never decode its wire values."""
247
+ artifact = program.get("artifact")
248
+ actual = program.get("outputs")
249
+ if type(artifact) is not dict or type(actual) is not list or len(actual) != len(expected):
250
+ raise ReadBuildError("original Truss binary inventory required")
251
+ columns, pins, plan = artifact.get("columns"), artifact.get("modelPins"), artifact.get("logicalPlan")
252
+ if type(columns) is not list or type(pins) is not list or type(plan) is not dict:
253
+ raise ReadBuildError("original Truss binary source custody required")
254
+ graph, projections = plan.get("typeGraph"), plan.get("outputs")
255
+ page_program = program["version"] == "weft.engine-page/0.2"
256
+ if (type(graph) is not list or type(projections) is not list
257
+ or len(projections) < len(actual) or not page_program and len(projections) != len(actual)):
258
+ raise ReadBuildError("original Truss binary projection inventory required")
259
+ projections = projections[:len(actual)]
260
+ for output, wanted, projection in zip(actual, expected, projections, strict=True):
261
+ if type(output) is not dict or output.get("name") != wanted["name"]:
262
+ raise ReadBuildError("original Truss output differs")
263
+ if wanted["carrier"] != "binary":
264
+ expression = projection.get("expression") if type(projection) is dict else None
265
+ source = expression.get("identity") if type(expression) is dict else None
266
+ types = [t for t in graph if type(t) is dict and t.get("identity") == source]
267
+ native = [c for c in columns if type(c) is dict and c.get("outputName") == output["name"]]
268
+ if (set(output) != {"name", "carrier", "nullable", "missing", "source", "representation", "modelPins"}
269
+ or type(output["nullable"]) is not bool or type(output["missing"]) is not bool
270
+ or output["carrier"] != wanted["carrier"] or output["nullable"] and not wanted["nullable"]
271
+ or output["missing"] and not wanted["missing"] or output["source"] != source or output["modelPins"] != pins
272
+ or type(expression) is not dict or expression.get("op") != "field"
273
+ or type(source) is not dict or len(types) != 1 or len(native) != 1
274
+ or native[0].get("sourceIdentities") != [source] or native[0].get("representation") != output["representation"]
275
+ or types[0].get("kind") != "scalar" or type(types[0].get("type")) is not dict
276
+ or types[0].get("availability") not in ("required", "absent-allowed")):
277
+ raise ReadBuildError("original direct scalar sibling presence proof required")
278
+ logical = types[0]["type"]
279
+ representation = native[0]["representation"]
280
+ missing = types[0]["availability"] == "absent-allowed"
281
+ if (logical.get("family") != output["carrier"] or logical.get("nullable") is not False
282
+ or output["missing"] != missing or output["nullable"] != missing
283
+ or type(representation) is not dict
284
+ or not (not missing and representation.get("kind") == "scalar" and representation.get("logicalType") == logical
285
+ or representation == {"kind": "value", "descriptor": source, "nativeNull": True})):
286
+ raise ReadBuildError("original current-core scalar sibling state domain differs")
287
+ _truss_field_source(source, pins, program)
288
+ continue
289
+ if (set(output) != {"name", "carrier", "nullable", "missing", "source", "representation", "modelPins", "stateDomain", "decoder"}
290
+ or output["carrier"] != "binary" or type(output["nullable"]) is not bool or type(output["missing"]) is not bool
291
+ or output["nullable"] and not wanted["nullable"] or output["missing"] and not wanted["missing"]
292
+ or output["decoder"] != {"profile": "truss-binary/0.1"} or output["modelPins"] != pins):
293
+ raise ReadBuildError("closed original Truss binary descriptor required")
294
+ source = output["source"]
295
+ if type(source) is not dict or set(source) != {"documentId", "revision", "module", "element"}:
296
+ raise ReadBuildError("original Truss binary Field required")
297
+ types = [t for t in graph if type(t) is dict and t.get("identity") == source]
298
+ native = [c for c in columns if type(c) is dict and c.get("outputName") == output["name"]]
299
+ if (len(types) != 1 or types[0].get("kind") != "exactScalar" or types[0].get("scalarType") != "binary"
300
+ or types[0].get("availability") not in ("required", "absent-allowed") or len(native) != 1
301
+ or native[0].get("sourceIdentities") != [source] or native[0].get("representation") != output["representation"]
302
+ or type(projection) is not dict or projection.get("name") != output["name"]
303
+ or projection.get("expression", {}).get("op") != "field" or projection["expression"].get("identity") != source):
304
+ raise ReadBuildError("original Truss binary projection/source differs")
305
+ optional = types[0]["availability"] == "absent-allowed"
306
+ if (output["nullable"] != optional or output["missing"] != optional
307
+ or output["stateDomain"] != {"version": "umf.core08-binary/0.1", "states": ["missing", "null", "value"] if optional else ["value"]}
308
+ or output["representation"] != {"kind": "value", "descriptor": source, "nativeNull": True}):
309
+ raise ReadBuildError("original current-core binary state domain differs")
310
+ _truss_field_source(source, pins, program)
311
+ if program["version"] == "weft.engine-page/0.2":
312
+ selected = _selected_key(program.get("selectedKey"))
313
+ key, page = plan.get("pageKey"), program.get("page")
314
+ record = plan.get("source", {}).get("record", {})
315
+ if (type(key) is not dict or type(page) is not dict or key.get("id") != selected["key"]
316
+ or selected["module"] != record.get("module") or selected["record"] != record.get("element")
317
+ or page.get("visibleOutputs") != len(actual) or type(page.get("keyOutputs")) is not list
318
+ or len(page["keyOutputs"]) != len(key.get("fields", []))):
319
+ raise ReadBuildError("original Truss authored page Key differs")
320
+ for index, identity in zip(page["keyOutputs"], key["fields"], strict=True):
321
+ if type(index) is not int or not 0 <= index < len(columns) or columns[index].get("sourceIdentities") != [identity]:
322
+ raise ReadBuildError("original Truss hidden Key output differs")
323
+
324
+
325
+ def _selected_key(value: object) -> dict[str, str]:
326
+ if (not isinstance(value, Mapping) or set(value) != {"module", "record", "key"}
327
+ or any(type(v) is not str or not v for v in value.values())):
328
+ raise ReadBuildError("closed original selected Key required")
329
+ return dict(value)
330
+
331
+
332
+ def _related_packet(request: Mapping[str, Any], source: object, relationship: object, method: str, page_size: int | None = None, selected_key: Mapping[str, str] | None = None, source_selected_key: Mapping[str, str] | None = None, order_key: Mapping[str, str] | None = None) -> dict[str, Any]:
333
+ """Retain both complete original requests; composition remains compiler-owned."""
334
+ methods = ("truss-runtime", "ashlar-spark4", "ashlar-dbsql-20261016", "ashlar-spark4-pages", "ashlar-dbsql-20261016-pages") if page_size is None else ("truss-runtime", "ashlar-spark4-pages", "ashlar-dbsql-20261016-pages")
335
+ successor = method in ("ashlar-spark4-sdk", "ashlar-spark4-sdk-pages")
336
+ if successor:
337
+ if page_size is not None and order_key is not None:
338
+ raise ReadBuildError("order Key is ordinary-read only")
339
+ if page_size is not None and method != "ashlar-spark4-sdk-pages":
340
+ raise ReadBuildError("original engine page compiler required")
341
+ source_key = _selected_key(source_selected_key)
342
+ target_key = _selected_key(selected_key) if page_size is not None else None
343
+ if page_size is None and selected_key is not None:
344
+ raise ReadBuildError("selected Key is page-only")
345
+ elif selected_key is not None or source_selected_key is not None or order_key is not None:
346
+ raise ReadBuildError("legacy engine selector rejects selected Keys")
347
+ if not successor and method not in methods:
348
+ raise ReadBuildError("WEFT_BLOCKED: original engine navigation compiler profile required")
349
+ if not isinstance(request, Mapping) or not isinstance(source, Mapping) or not isinstance(relationship, Mapping) or set(relationship)!={"module","id","direction"} or any(type(relationship[name]) is not str or not relationship[name] for name in relationship) or relationship["direction"] not in ("forward","inverse"):
350
+ raise ReadBuildError("closed original directed relationship identity required")
351
+ if type(request.get("sql")) is not str or type(source.get("sql")) is not str:
352
+ raise ReadBuildError("both original logical source and target queries required")
353
+ if canonical_json({k:v for k,v in source.items() if k!="sql"}) != canonical_json({k:v for k,v in request.items() if k!="sql"}):
354
+ raise ReadBuildError("original engine navigation requests must share exact context and parameter inventory")
355
+ return {"version":("weft.engine-related-page/" if page_size is not None else "weft.engine-related-read/") + ("0.2" if successor else "0.1"), **({"sourceSelectedKey": source_key} if successor else {}), **({"selectedKey": target_key} if successor and page_size is not None else {}), **({"orderKey": _selected_key(order_key)} if order_key is not None else {}), "compiler":method,"source":dict(source),"target":dict(request),"relationship":dict(relationship), **({"pageSize": page_size} if page_size is not None else {})}
356
+
357
+
358
+ @dataclass(frozen=True)
359
+ class EngineRead(CatalogRead[P, R]):
360
+ @classmethod
361
+ def build(
362
+ cls,
363
+ compiler: Any,
364
+ request: Mapping[str, Any],
365
+ *,
366
+ parameters: type[P],
367
+ result: type[R],
368
+ method: str,
369
+ page_size: int | None = None,
370
+ related_source: Mapping[str, Any] | None = None,
371
+ relationship: Mapping[str, str] | None = None,
372
+ selected_key: Mapping[str, str] | None = None,
373
+ source_selected_key: Mapping[str, str] | None = None,
374
+ order_key: Mapping[str, str] | None = None,
375
+ ) -> EngineRead[P, R]:
376
+ original = cls.compile_original(compiler, request, method=method, page_size=page_size, related_source=related_source, relationship=relationship, selected_key=selected_key, source_selected_key=source_selected_key, order_key=order_key)
377
+ return cls.from_original(original, parameters=parameters, result=result)
378
+
379
+ @classmethod
380
+ def compile_original(
381
+ cls,
382
+ compiler: Any,
383
+ request: Mapping[str, Any],
384
+ *,
385
+ method: str,
386
+ page_size: int | None = None,
387
+ related_source: Mapping[str, Any] | None = None,
388
+ relationship: Mapping[str, str] | None = None,
389
+ selected_key: Mapping[str, str] | None = None,
390
+ source_selected_key: Mapping[str, str] | None = None,
391
+ order_key: Mapping[str, str] | None = None,
392
+ ) -> str:
393
+ """Obtain one untouched owner program before choosing typed transport."""
394
+ if (related_source is None) != (relationship is None):
395
+ raise ReadBuildError("both original navigation source and relationship are required")
396
+ successor = method in ("ashlar-spark4-sdk", "ashlar-spark4-sdk-pages", "truss-runtime-binary")
397
+ if not successor and (selected_key is not None or source_selected_key is not None or order_key is not None):
398
+ raise ReadBuildError("legacy engine selector rejects selected Keys")
399
+ if page_size is None and selected_key is not None:
400
+ raise ReadBuildError("selected Key is page-only")
401
+ if related_source is None and source_selected_key is not None:
402
+ raise ReadBuildError("source selected Key is navigation-only")
403
+ if page_size is not None and order_key is not None:
404
+ raise ReadBuildError("order Key is ordinary-read only")
405
+ ordering_key = _selected_key(order_key) if order_key is not None else None
406
+ key = _selected_key(selected_key) if successor and page_size is not None else None
407
+ if method == "truss-runtime-binary" and (related_source is not None or order_key is not None):
408
+ raise ReadBuildError("explicit Truss binary profile has no navigation/ordered-read extension")
409
+ related = related_source is not None
410
+ packet = _related_packet(request, related_source, relationship, method, page_size, selected_key, source_selected_key, order_key) if related_source is not None and relationship is not None else None
411
+ if page_size is not None and (type(page_size) is not int or not 1 <= page_size <= 999 or method not in ("truss-runtime", "ashlar-spark4-pages", "ashlar-dbsql-20261016-pages", "ashlar-spark4-sdk-pages", "truss-runtime-binary")):
412
+ raise ReadBuildError("original engine page size must be in 1..999")
413
+ compile_method = getattr(compiler, ("compile_engine_related_page_json" if page_size is not None else "compile_engine_related_read_json") if related else "compile_engine_page_json" if page_size is not None else "compile_engine_read_json", None)
414
+ if not callable(compile_method):
415
+ raise ReadBuildError(
416
+ "WEFT_BLOCKED: original engine catalog compiler required"
417
+ )
418
+ original = compile_method(
419
+ canonical_json(
420
+ packet if packet is not None else {
421
+ "version": ("weft.engine-page/" if page_size is not None else "weft.engine-read/") + ("0.2" if successor else "0.1"),
422
+ **({"selectedKey": key} if key is not None else {}),
423
+ **({"orderKey": ordering_key} if ordering_key is not None else {}),
424
+ **({"pageSize": page_size} if page_size is not None else {}),
425
+ "compiler": method,
426
+ "request": dict(request),
427
+ }
428
+ )
429
+ )
430
+ program = program_json(original)
431
+ if type(program) is not dict:
432
+ raise ReadBuildError("original engine program object required")
433
+ if program.get("status") != "compiled":
434
+ raise ProgramBuildError(original)
435
+ if canonical_json(program.get("request")) != canonical_json(dict(request)) or program.get("compiler") != method or (page_size is not None and program.get("pageSize") != page_size):
436
+ raise ReadBuildError("original engine request or page bound differs")
437
+ if ordering_key is not None and program.get("orderKey") != ordering_key:
438
+ raise ReadBuildError("original order Key differs")
439
+ if key is not None and program.get("selectedKey") != key:
440
+ raise ReadBuildError("original selected Key differs")
441
+ if packet is not None and canonical_json(program.get("relatedRequest")) != canonical_json(packet):
442
+ raise ReadBuildError("original engine navigation packet differs")
443
+ return original
444
+
445
+ @classmethod
446
+ def from_original(
447
+ cls, original: str, *, parameters: type[P], result: type[R]
448
+ ) -> EngineRead[P, R]:
449
+ """Wrap original bytes; artifact and native authority guards still apply."""
450
+ if type(original) is not str or len(original.encode()) > 4_194_304:
451
+ raise ReadBuildError("bounded original engine program required")
452
+ parsed = program_json(original)
453
+ if type(parsed) is not dict:
454
+ raise ReadBuildError("original engine program object required")
455
+ successor = parsed.get("version") in ("weft.engine-read/0.2", "weft.engine-page/0.2")
456
+ binary = parsed.get("compiler") == "truss-runtime-binary"
457
+ wrapper = {
458
+ "version": "umf.engine-catalog/0.2" if successor else "umf.engine-catalog/0.1",
459
+ "programJson": original,
460
+ "parameters": _fields(parameters),
461
+ "outputs": _engine_fields(result, allow_binary=binary) if successor else _fields(result, parameter=False, allow_related=True),
462
+ "stageOne": _generation(parameters, result),
463
+ }
464
+ wrapper["catalogDigest"] = hashlib.sha256(
465
+ canonical_json(wrapper).encode()
466
+ ).hexdigest()
467
+ entry = cls(canonical_json(wrapper), parameters, result)
468
+ entry.artifact()
469
+ return entry
470
+
471
+ def originals(self) -> str:
472
+ self.artifact()
473
+ return program_json(self.artifact_json)["programJson"]
474
+
475
+ def artifact(self) -> dict[str, Any]:
476
+ wrapper = program_json(self.artifact_json)
477
+ if type(wrapper) is not dict:
478
+ raise ReadBuildError("engine catalog object required")
479
+ if (
480
+ set(wrapper)
481
+ != {
482
+ "version",
483
+ "programJson",
484
+ "parameters",
485
+ "outputs",
486
+ "stageOne",
487
+ "catalogDigest",
488
+ }
489
+ or wrapper["version"] not in ("umf.engine-catalog/0.1", "umf.engine-catalog/0.2")
490
+ ):
491
+ raise ReadBuildError("closed engine catalog required")
492
+ digest = wrapper.pop("catalogDigest")
493
+ if digest != hashlib.sha256(canonical_json(wrapper).encode()).hexdigest():
494
+ raise ReadBuildError("engine catalog digest differs")
495
+ if wrapper["stageOne"] != _generation(self.parameters, self.result):
496
+ raise ReadBuildError("CATALOG_STALE: engine loaded generation differs")
497
+ original = wrapper["programJson"]
498
+ if type(original) is not str or len(original.encode()) > 4_194_304:
499
+ raise ReadBuildError("bounded original engine program required")
500
+ program = program_json(original)
501
+ if type(program) is not dict:
502
+ raise ReadBuildError("original engine program object required")
503
+ if wrapper["parameters"] != _fields(self.parameters) or wrapper[
504
+ "outputs"
505
+ ] != (_engine_fields(self.result, allow_binary=program.get("compiler") == "truss-runtime-binary") if wrapper["version"] == "umf.engine-catalog/0.2" else _fields(self.result, parameter=False, allow_related=True)):
506
+ raise ReadBuildError("engine model signature differs")
507
+ if (
508
+ program.get("version") not in ("weft.engine-read/0.1", "weft.engine-page/0.1", "weft.engine-read/0.2", "weft.engine-page/0.2")
509
+ or program.get("status") != "compiled"
510
+ ):
511
+ raise ReadBuildError("original compiled engine program required")
512
+ compiler_id = program.get("compiler")
513
+ if type(compiler_id) is not str:
514
+ raise ReadBuildError("original engine compiler identity required")
515
+ successor = program["version"] in ("weft.engine-read/0.2", "weft.engine-page/0.2")
516
+ if (wrapper["version"] == "umf.engine-catalog/0.2") != successor:
517
+ raise ReadBuildError("engine wrapper and original program versions differ")
518
+ if successor and program.get("compiler") not in ("ashlar-spark4-sdk", "ashlar-spark4-sdk-pages", "truss-runtime-binary"):
519
+ raise ReadBuildError("explicit original engine0.2 compiler profile required")
520
+ page = program["version"] in ("weft.engine-page/0.1", "weft.engine-page/0.2")
521
+ if successor:
522
+ if page:
523
+ _selected_key(program.get("selectedKey"))
524
+ if "orderKey" in program:
525
+ raise ReadBuildError("page original cannot carry ordinary order Key")
526
+ elif "selectedKey" in program:
527
+ raise ReadBuildError("ordinary original cannot carry page selected Key")
528
+ elif "orderKey" in program:
529
+ _selected_key(program["orderKey"])
530
+ if page and (program.get("after") is not None or type(program.get("pageSize")) is not int or not 1 <= program["pageSize"] <= 999 or program.get("compiler") not in ("truss-runtime", "ashlar-spark4-pages", "ashlar-dbsql-20261016-pages", "ashlar-spark4-sdk-pages", "truss-runtime-binary")):
531
+ raise ReadBuildError("original first-page engine catalog required")
532
+ if "relatedRequest" in program:
533
+ packet = program["relatedRequest"]
534
+ if type(packet) is not dict:
535
+ raise ReadBuildError("closed original engine navigation packet required")
536
+ fields = {"version","compiler","source","target","relationship"} | ({"pageSize"} if page else set()) | ({"sourceSelectedKey"} | ({"selectedKey"} if page else set()) if successor else set()) | ({"orderKey"} if "orderKey" in packet else set())
537
+ if type(packet) is not dict or set(packet) != fields:
538
+ raise ReadBuildError("closed original engine navigation packet required")
539
+ expected = _related_packet(program["request"], packet.get("source"), packet.get("relationship"), compiler_id, program.get("pageSize") if page else None, packet.get("selectedKey"), packet.get("sourceSelectedKey"), packet.get("orderKey"))
540
+ if canonical_json(packet) != canonical_json(expected):
541
+ raise ReadBuildError("original engine navigation packet differs")
542
+ structural = dict(program)
543
+ pin = structural.pop("structuralDigest", None)
544
+ if pin != {
545
+ "owner": "weft-runtime-engine-page" if page else "weft-runtime-engine-read",
546
+ "version": "0.2" if successor else "0.1",
547
+ "sha256": hashlib.sha256(canonical_json(structural).encode()).hexdigest(),
548
+ }:
549
+ raise ReadBuildError("original engine compiler digest differs")
550
+ if successor and program.get("compiler") == "truss-runtime-binary":
551
+ _truss_binary_output_custody(program, wrapper["outputs"])
552
+ elif successor:
553
+ _engine_output_custody(program, wrapper["outputs"])
554
+ elif not _compatible_outputs(program.get("outputs"), wrapper["outputs"]):
555
+ raise ReadBuildError("engine output types differ from generated view")
556
+ declared = {p["name"]: p for p in wrapper["parameters"]}
557
+ native = program["request"]["parameters"]
558
+ if set(declared) != set(native) or any(
559
+ native[n]["family"] != p["carrier"] or p["nullable"]
560
+ for n, p in declared.items()
561
+ ):
562
+ raise ReadBuildError("engine parameter signatures differ")
563
+ return program
@@ -0,0 +1,5 @@
1
+ # SPDX-License-Identifier: MIT OR Apache-2.0
2
+ # Generated from spec/metamodel/umf.yaml; model 42144576e3b15da4945ca744623a31967e3b29efa54da8ba3961e446b1c0e34b; compiler 906cd23c97dc5c1f2d63c269999b86a7bb21f348ad6579bd2347218714d796bb
3
+ from typing import Final, Literal, TypeAlias
4
+ CURRENT_CORE_VERSION: Final = "0.10.0"
5
+ CoreVersion: TypeAlias = Literal["0.10.0"]
@@ -0,0 +1,46 @@
1
+ # SPDX-License-Identifier: MIT OR Apache-2.0
2
+ """Administrative table lifecycle and head observation; no implicit pool or driver."""
3
+ from .approval import ApprovalBinding, ApprovalReceipt, TargetIdentity
4
+ from .catalog import CatalogError, verify_native_catalog
5
+ from .concurrent import apply_concurrent_indexes
6
+ from .correspondence import prepare_table_correspondence
7
+ from .generation_ingress import (
8
+ EpochProvisionRequest,
9
+ EpochProvisionReservation,
10
+ GenerationAdmission,
11
+ GenerationEnrollment,
12
+ GenerationFenceReceipt,
13
+ GenerationIngressLease,
14
+ GenerationIngressProvider,
15
+ GenerationIngressRequest,
16
+ GenerationObservation,
17
+ GenerationTransition,
18
+ OwnerEnrollmentRequest,
19
+ PreparedGenerationEpoch,
20
+ TargetCustodian,
21
+ TargetCustody,
22
+ TargetReservation,
23
+ )
24
+ from .head import prepare_table_head, read_table_head
25
+ from .host import (
26
+ HostCapabilities,
27
+ HostOutcomeUnknown,
28
+ MigrationHost,
29
+ MigrationRequest,
30
+ PsycopgMigrationHost,
31
+ apply_migration_on_host,
32
+ )
33
+ from .ledger import apply_table_migration, inspect_table_history
34
+ from .mixed import apply_mixed_migration
35
+ from .phase_policy import (
36
+ DERIVED_ADMIN_MODULE_PROFILE,
37
+ FieldReplacementExecutionPolicy,
38
+ PhaseBudgetCounter,
39
+ PhaseDeadline,
40
+ validate_phase_budget_receipt,
41
+ )
42
+ from .privileges import verify_native_privileges
43
+ from .roles import verify_native_role_scope
44
+ from .sql_containment import ContainmentRefused, SqlParser, check_sql_containment
45
+
46
+ __all__ = ["DERIVED_ADMIN_MODULE_PROFILE", "ApprovalBinding", "ApprovalReceipt", "CatalogError", "ContainmentRefused", "EpochProvisionRequest", "EpochProvisionReservation", "FieldReplacementExecutionPolicy", "GenerationAdmission", "GenerationEnrollment", "GenerationFenceReceipt", "GenerationIngressLease", "GenerationIngressProvider", "GenerationIngressRequest", "GenerationObservation", "GenerationTransition", "HostCapabilities", "HostOutcomeUnknown", "MigrationHost", "MigrationRequest", "OwnerEnrollmentRequest", "PhaseBudgetCounter", "PhaseDeadline", "PreparedGenerationEpoch", "PsycopgMigrationHost", "SqlParser", "TargetCustodian", "TargetCustody", "TargetIdentity", "TargetReservation", "apply_concurrent_indexes", "apply_migration_on_host", "apply_mixed_migration", "apply_table_migration", "check_sql_containment", "inspect_table_history", "prepare_table_correspondence", "prepare_table_head", "read_table_head", "validate_phase_budget_receipt", "verify_native_catalog", "verify_native_privileges", "verify_native_role_scope"]