parallax-snapshot 0.1.0__tar.gz
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.
- parallax_snapshot-0.1.0/.gitignore +16 -0
- parallax_snapshot-0.1.0/LICENSE +201 -0
- parallax_snapshot-0.1.0/NOTICE +5 -0
- parallax_snapshot-0.1.0/PKG-INFO +26 -0
- parallax_snapshot-0.1.0/README.md +11 -0
- parallax_snapshot-0.1.0/pyproject.toml +27 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/__init__.py +78 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_handle/__init__.py +1 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_handle/_database.py +222 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_handle/_errors.py +49 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_handle/_read.py +674 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_handle/_sources.py +150 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_handle/_stream.py +305 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_handle/_transaction.py +606 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_handle/_typed_writes.py +422 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_handle/_wire.py +425 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_handle/_wire_writes.py +739 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_inspection.py +520 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_publication/__init__.py +1 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_publication/_classify.py +124 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_publication/_root.py +634 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_publication/_root_publication.py +111 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_publication/_typed.py +168 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_publication/_wire.py +816 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_publication/_wire_memo.py +103 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/_publication/_wire_render.py +454 -0
- parallax_snapshot-0.1.0/src/parallax/snapshot/py.typed +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Python build / test artifacts (uv, hatchling, pytest-cov, pyright).
|
|
2
|
+
.venv/
|
|
3
|
+
__pycache__/
|
|
4
|
+
*.pyc
|
|
5
|
+
*.egg-info/
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
coverage.xml
|
|
9
|
+
.coverage
|
|
10
|
+
.coverage.*
|
|
11
|
+
.pytest_cache/
|
|
12
|
+
.ruff_cache/
|
|
13
|
+
# An editable install compiles parallax-postgres's Cython sources in place.
|
|
14
|
+
packages/parallax-postgres/src/**/*.c
|
|
15
|
+
*.so
|
|
16
|
+
*.pyd
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: parallax-snapshot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Parallax snapshot lifecycle extension: Snapshot[T] materialization and the developer handle over the parallax-core spine.
|
|
5
|
+
Project-URL: Documentation, https://github.com/davidsunglee/parallax/blob/main/languages/python/docs/guide/README.md
|
|
6
|
+
Project-URL: Repository, https://github.com/davidsunglee/parallax
|
|
7
|
+
Project-URL: Changelog, https://github.com/davidsunglee/parallax/blob/main/languages/python/docs/releases.md
|
|
8
|
+
Author: Parallax
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: NOTICE
|
|
12
|
+
Requires-Python: >=3.14
|
|
13
|
+
Requires-Dist: parallax-core==0.1.0
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# parallax-snapshot
|
|
17
|
+
|
|
18
|
+
Parallax snapshot lifecycle extension over `parallax-core`. See the [Python binding](https://github.com/davidsunglee/parallax/blob/main/languages/python/spec/python.md).
|
|
19
|
+
|
|
20
|
+
Install this distribution with `python -m pip install parallax-snapshot==0.1.0`.
|
|
21
|
+
Its metadata installs exact matching first-party dependencies. The
|
|
22
|
+
[getting-started guide](https://github.com/davidsunglee/parallax/blob/main/languages/python/docs/guide/01-getting-started.md#install)
|
|
23
|
+
explains application composition and supported environments; the
|
|
24
|
+
[release notes](https://github.com/davidsunglee/parallax/blob/main/languages/python/docs/releases.md) record publication status.
|
|
25
|
+
|
|
26
|
+
Licensed under Apache-2.0; the distribution includes `LICENSE` and `NOTICE`.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# parallax-snapshot
|
|
2
|
+
|
|
3
|
+
Parallax snapshot lifecycle extension over `parallax-core`. See the [Python binding](https://github.com/davidsunglee/parallax/blob/main/languages/python/spec/python.md).
|
|
4
|
+
|
|
5
|
+
Install this distribution with `python -m pip install parallax-snapshot==0.1.0`.
|
|
6
|
+
Its metadata installs exact matching first-party dependencies. The
|
|
7
|
+
[getting-started guide](https://github.com/davidsunglee/parallax/blob/main/languages/python/docs/guide/01-getting-started.md#install)
|
|
8
|
+
explains application composition and supported environments; the
|
|
9
|
+
[release notes](https://github.com/davidsunglee/parallax/blob/main/languages/python/docs/releases.md) record publication status.
|
|
10
|
+
|
|
11
|
+
Licensed under Apache-2.0; the distribution includes `LICENSE` and `NOTICE`.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "parallax-snapshot"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Parallax snapshot lifecycle extension: Snapshot[T] materialization and the developer handle over the parallax-core spine."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.14"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
9
|
+
authors = [{ name = "Parallax" }]
|
|
10
|
+
dependencies = [
|
|
11
|
+
"parallax-core==0.1.0",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[project.urls]
|
|
15
|
+
Documentation = "https://github.com/davidsunglee/parallax/blob/main/languages/python/docs/guide/README.md"
|
|
16
|
+
Repository = "https://github.com/davidsunglee/parallax"
|
|
17
|
+
Changelog = "https://github.com/davidsunglee/parallax/blob/main/languages/python/docs/releases.md"
|
|
18
|
+
|
|
19
|
+
[build-system]
|
|
20
|
+
requires = ["hatchling"]
|
|
21
|
+
build-backend = "hatchling.build"
|
|
22
|
+
|
|
23
|
+
[tool.hatch.build.targets.wheel]
|
|
24
|
+
packages = ["src/parallax"]
|
|
25
|
+
|
|
26
|
+
[tool.hatch.build.targets.sdist]
|
|
27
|
+
include = ["src/parallax", "README.md", "LICENSE", "NOTICE"]
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
from parallax.core.temporal_read import Edge
|
|
2
|
+
from parallax.snapshot._handle._database import Database, ScopedDatabase, connect
|
|
3
|
+
from parallax.snapshot._handle._errors import (
|
|
4
|
+
SnapshotConnectionError,
|
|
5
|
+
SnapshotMaterializationError,
|
|
6
|
+
)
|
|
7
|
+
from parallax.snapshot._handle._read import (
|
|
8
|
+
CheckedSnapshot,
|
|
9
|
+
NoResultFound,
|
|
10
|
+
Snapshot,
|
|
11
|
+
TooManyResultsFound,
|
|
12
|
+
)
|
|
13
|
+
from parallax.snapshot._handle._stream import SnapshotStream
|
|
14
|
+
from parallax.snapshot._handle._transaction import ReadOnlyTxnContext, TxnContext
|
|
15
|
+
from parallax.snapshot._handle._wire import (
|
|
16
|
+
WireDatabaseView,
|
|
17
|
+
WireQuery,
|
|
18
|
+
WireTransactionView,
|
|
19
|
+
)
|
|
20
|
+
from parallax.snapshot._handle._wire_writes import WireChanges, WirePredicateTarget
|
|
21
|
+
from parallax.snapshot._inspection import (
|
|
22
|
+
SnapshotInspectionError,
|
|
23
|
+
is_view_loaded,
|
|
24
|
+
pin_of,
|
|
25
|
+
view,
|
|
26
|
+
)
|
|
27
|
+
from parallax.snapshot._inspection import edge_of as _typed_edge_of
|
|
28
|
+
from parallax.snapshot._publication._root import SnapshotConsistencyError
|
|
29
|
+
from parallax.snapshot._publication._wire import WireEntity, WireValue, wire_edge_of
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
"CheckedSnapshot",
|
|
33
|
+
"Database",
|
|
34
|
+
"NoResultFound",
|
|
35
|
+
"ReadOnlyTxnContext",
|
|
36
|
+
"ScopedDatabase",
|
|
37
|
+
"Snapshot",
|
|
38
|
+
"SnapshotConnectionError",
|
|
39
|
+
"SnapshotConsistencyError",
|
|
40
|
+
"SnapshotInspectionError",
|
|
41
|
+
"SnapshotMaterializationError",
|
|
42
|
+
"SnapshotStream",
|
|
43
|
+
"TooManyResultsFound",
|
|
44
|
+
"TxnContext",
|
|
45
|
+
"WireChanges",
|
|
46
|
+
"WireDatabaseView",
|
|
47
|
+
"WireEntity",
|
|
48
|
+
"WirePredicateTarget",
|
|
49
|
+
"WireQuery",
|
|
50
|
+
"WireTransactionView",
|
|
51
|
+
"WireValue",
|
|
52
|
+
"connect",
|
|
53
|
+
"edge_of",
|
|
54
|
+
"is_view_loaded",
|
|
55
|
+
"pin_of",
|
|
56
|
+
"view",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def edge_of(node: object) -> Edge:
|
|
61
|
+
"""``node``'s own milestone :class:`~parallax.core.temporal_read.Edge` — the
|
|
62
|
+
finite from-instant on every axis its family declares.
|
|
63
|
+
|
|
64
|
+
A Typed node a Snapshot read materialized, or any edit of it, shares the
|
|
65
|
+
Edge derived on first inspection; concurrent first inspections may each
|
|
66
|
+
derive an equal Edge, so identity is stable once they have all returned.
|
|
67
|
+
A Wire node a read published, a
|
|
68
|
+
diagnostic node of an invalid root included, answers equal Edges on
|
|
69
|
+
repeated calls, not necessarily one object. Inspection grants no write
|
|
70
|
+
authority; a caller may state the Edge's ``tx_time`` as a target write's
|
|
71
|
+
``tx_start`` condition.
|
|
72
|
+
"""
|
|
73
|
+
# Every Wire node is a frozen ``dict`` at runtime. Dispatching on that
|
|
74
|
+
# concrete base keeps a Typed node off the abstract ``WireEntity`` instance
|
|
75
|
+
# check, which alone would nearly double a cached Typed inspection.
|
|
76
|
+
if isinstance(node, dict):
|
|
77
|
+
return wire_edge_of(node) # pyright: ignore[reportUnknownArgumentType] - the Wire reader authenticates its own carrier
|
|
78
|
+
return _typed_edge_of(node)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__all__: list[str] = []
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
from typing import Any, cast
|
|
5
|
+
from uuid import uuid4
|
|
6
|
+
|
|
7
|
+
from parallax.core._execution._options import OMITTED, Omitted, TxnOptions
|
|
8
|
+
from parallax.core._execution._planning import prepare_model
|
|
9
|
+
from parallax.core._execution._publication import ServingModel
|
|
10
|
+
from parallax.core._execution._root import DatabaseRoot
|
|
11
|
+
from parallax.core._execution._routing import check_read_policy
|
|
12
|
+
from parallax.core._execution._scope import ExecutionScope
|
|
13
|
+
from parallax.core._execution._unit_work.clock import Clock
|
|
14
|
+
from parallax.core.auto_retry import RetryPolicy
|
|
15
|
+
from parallax.core.concurrency import ConcurrencyPreference
|
|
16
|
+
from parallax.core.db_port import DatabaseAdapter, DatabaseRuntime, IsolationLevel, RoutePolicy
|
|
17
|
+
from parallax.core.entity import DomainModel
|
|
18
|
+
from parallax.core.execution_lifecycle import ExecutionLifecycleProvider
|
|
19
|
+
from parallax.core.object_query import ObjectQueryNode
|
|
20
|
+
from parallax.core.object_query._fluent import ObjectQuery, typed_read_query
|
|
21
|
+
from parallax.core.read_delivery import RowsResult
|
|
22
|
+
from parallax.core.read_delivery._read_plan import (
|
|
23
|
+
DEFAULT_READ_PLAN_CACHE_CAPACITY,
|
|
24
|
+
check_read_plan_cache_capacity,
|
|
25
|
+
)
|
|
26
|
+
from parallax.snapshot._handle._errors import SnapshotConnectionError
|
|
27
|
+
from parallax.snapshot._handle._read import Snapshot, typed_publication_for
|
|
28
|
+
from parallax.snapshot._handle._stream import DEFAULT_BATCH_SIZE, SnapshotStream
|
|
29
|
+
from parallax.snapshot._handle._transaction import (
|
|
30
|
+
ReadOnlyTxnContext,
|
|
31
|
+
TxnContext,
|
|
32
|
+
read_only_context_for,
|
|
33
|
+
transaction_for,
|
|
34
|
+
)
|
|
35
|
+
from parallax.snapshot._handle._wire import WireDatabaseView
|
|
36
|
+
|
|
37
|
+
__all__ = ["Database", "ScopedDatabase", "connect"]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
_CONNECT_REFUSAL = (
|
|
41
|
+
"connect() takes a Domain Model — one composed from Entity Classes, or one a descriptor "
|
|
42
|
+
"produced — or a ServingModel holding a prepared one "
|
|
43
|
+
"(snapshot-class-backed-model-required); a bare accepted Metamodel is a form no "
|
|
44
|
+
"application holds"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
_CONSTRUCTOR_REFUSAL = (
|
|
48
|
+
"a Database connects to a Domain Model — one composed from Entity Classes, or one a "
|
|
49
|
+
"descriptor produced — or to a ServingModel holding a prepared one; a bare accepted "
|
|
50
|
+
"Metamodel names no model a connection can serve (snapshot-class-backed-model-required)"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def served_model(model: DomainModel | ServingModel, refusal: str) -> ServingModel:
|
|
55
|
+
"""Return the Serving Model a root will own, preparing static models once."""
|
|
56
|
+
if isinstance(model, ServingModel):
|
|
57
|
+
return model
|
|
58
|
+
if not isinstance(model, DomainModel): # pyright: ignore[reportUnnecessaryIsInstance]
|
|
59
|
+
raise SnapshotConnectionError(refusal)
|
|
60
|
+
return ServingModel(prepare_model(model, edition=f"static-{uuid4().hex}"))
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class ScopedDatabase:
|
|
64
|
+
"""An immutable, connectionless execution view with captured authority."""
|
|
65
|
+
|
|
66
|
+
__slots__ = ("_execution",)
|
|
67
|
+
|
|
68
|
+
_execution: ExecutionScope
|
|
69
|
+
|
|
70
|
+
def __init__(self) -> None:
|
|
71
|
+
raise TypeError("ScopedDatabase values are created by Database authority selection")
|
|
72
|
+
|
|
73
|
+
def __setattr__(self, name: str, value: object) -> None:
|
|
74
|
+
del name, value
|
|
75
|
+
raise AttributeError("ScopedDatabase is immutable")
|
|
76
|
+
|
|
77
|
+
@classmethod
|
|
78
|
+
def create(cls, execution: ExecutionScope) -> ScopedDatabase:
|
|
79
|
+
scoped = object.__new__(cls)
|
|
80
|
+
object.__setattr__(scoped, "_execution", execution)
|
|
81
|
+
return scoped
|
|
82
|
+
|
|
83
|
+
def with_options(
|
|
84
|
+
self,
|
|
85
|
+
*,
|
|
86
|
+
retry: RetryPolicy | Omitted = OMITTED,
|
|
87
|
+
concurrency: ConcurrencyPreference | Omitted = OMITTED,
|
|
88
|
+
isolation: IsolationLevel | Omitted = OMITTED,
|
|
89
|
+
) -> ScopedDatabase:
|
|
90
|
+
return self.create(
|
|
91
|
+
self._execution.with_options(
|
|
92
|
+
retry=retry,
|
|
93
|
+
concurrency=concurrency,
|
|
94
|
+
isolation=isolation,
|
|
95
|
+
)
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
def with_routing(self, *, read_policy: RoutePolicy) -> ScopedDatabase:
|
|
99
|
+
return self.create(self._execution.with_routing(read_policy=read_policy))
|
|
100
|
+
|
|
101
|
+
def find[S](self, query: ObjectQuery[Any, S]) -> Snapshot[S]:
|
|
102
|
+
return cast(
|
|
103
|
+
"Snapshot[S]",
|
|
104
|
+
self._execution.read(
|
|
105
|
+
query, convert_query=typed_read_query, build_publication=typed_publication_for
|
|
106
|
+
),
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
def stream[S](
|
|
110
|
+
self, query: ObjectQuery[Any, S], *, batch_size: int = DEFAULT_BATCH_SIZE
|
|
111
|
+
) -> SnapshotStream[S]:
|
|
112
|
+
return SnapshotStream(
|
|
113
|
+
self._execution,
|
|
114
|
+
query,
|
|
115
|
+
batch_size,
|
|
116
|
+
convert_query=typed_read_query,
|
|
117
|
+
build_publication=typed_publication_for,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
@property
|
|
121
|
+
def wire(self) -> WireDatabaseView:
|
|
122
|
+
return WireDatabaseView(self._execution)
|
|
123
|
+
|
|
124
|
+
def read_rows(self, query: ObjectQueryNode) -> RowsResult:
|
|
125
|
+
return self._execution.read_rows(query)
|
|
126
|
+
|
|
127
|
+
def transact[T](
|
|
128
|
+
self,
|
|
129
|
+
fn: Callable[[TxnContext], T],
|
|
130
|
+
/,
|
|
131
|
+
*,
|
|
132
|
+
retry: RetryPolicy | Omitted = OMITTED,
|
|
133
|
+
concurrency: ConcurrencyPreference | Omitted = OMITTED,
|
|
134
|
+
isolation: IsolationLevel | Omitted = OMITTED,
|
|
135
|
+
) -> T:
|
|
136
|
+
return self._execution.transact(
|
|
137
|
+
fn,
|
|
138
|
+
transaction_for,
|
|
139
|
+
retry=retry,
|
|
140
|
+
concurrency=concurrency,
|
|
141
|
+
isolation=isolation,
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
def read_only[T](
|
|
145
|
+
self,
|
|
146
|
+
fn: Callable[[ReadOnlyTxnContext], T],
|
|
147
|
+
/,
|
|
148
|
+
*,
|
|
149
|
+
retry: RetryPolicy | Omitted = OMITTED,
|
|
150
|
+
isolation: IsolationLevel | Omitted = OMITTED,
|
|
151
|
+
) -> T:
|
|
152
|
+
return self._execution.read_only(
|
|
153
|
+
fn, read_only_context_for, retry=retry, isolation=isolation
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class Database[Authorization](DatabaseRoot[Authorization, ScopedDatabase]):
|
|
158
|
+
"""Owns a runtime; close it explicitly or use it as a context manager.
|
|
159
|
+
|
|
160
|
+
Option and routing aliases and execution scopes share that runtime. Closing
|
|
161
|
+
any root alias closes it for all of them; creating a scope acquires no
|
|
162
|
+
connection.
|
|
163
|
+
"""
|
|
164
|
+
|
|
165
|
+
__slots__ = ()
|
|
166
|
+
|
|
167
|
+
def __init__(
|
|
168
|
+
self,
|
|
169
|
+
runtime: DatabaseRuntime[Authorization],
|
|
170
|
+
model: DomainModel | ServingModel,
|
|
171
|
+
*,
|
|
172
|
+
options: TxnOptions | None = None,
|
|
173
|
+
read_policy: RoutePolicy | None = None,
|
|
174
|
+
read_plan_cache_capacity: int = DEFAULT_READ_PLAN_CACHE_CAPACITY,
|
|
175
|
+
clock: Clock | None = None,
|
|
176
|
+
lifecycle_provider: ExecutionLifecycleProvider | None = None,
|
|
177
|
+
) -> None:
|
|
178
|
+
capacity = check_read_plan_cache_capacity(read_plan_cache_capacity)
|
|
179
|
+
super().__init__(
|
|
180
|
+
runtime,
|
|
181
|
+
served_model(model, _CONSTRUCTOR_REFUSAL),
|
|
182
|
+
scope_for=ScopedDatabase.create,
|
|
183
|
+
options=options,
|
|
184
|
+
read_policy=read_policy,
|
|
185
|
+
read_plan_cache_capacity=capacity,
|
|
186
|
+
clock=clock,
|
|
187
|
+
lifecycle_provider=lifecycle_provider,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
@classmethod
|
|
191
|
+
def connect[Auth](
|
|
192
|
+
cls,
|
|
193
|
+
adapter: DatabaseAdapter[Auth],
|
|
194
|
+
model: DomainModel | ServingModel,
|
|
195
|
+
*,
|
|
196
|
+
options: TxnOptions | None = None,
|
|
197
|
+
read_policy: RoutePolicy | None = None,
|
|
198
|
+
read_plan_cache_capacity: int = DEFAULT_READ_PLAN_CACHE_CAPACITY,
|
|
199
|
+
clock: Clock | None = None,
|
|
200
|
+
lifecycle_provider: ExecutionLifecycleProvider | None = None,
|
|
201
|
+
) -> Database[Auth]:
|
|
202
|
+
capacity = check_read_plan_cache_capacity(read_plan_cache_capacity)
|
|
203
|
+
serving = served_model(model, _CONNECT_REFUSAL)
|
|
204
|
+
defaults = options if options is not None else TxnOptions()
|
|
205
|
+
policy = check_read_policy(read_policy)
|
|
206
|
+
runtime = adapter.open()
|
|
207
|
+
try:
|
|
208
|
+
return Database(
|
|
209
|
+
runtime,
|
|
210
|
+
serving,
|
|
211
|
+
options=defaults,
|
|
212
|
+
read_policy=policy,
|
|
213
|
+
read_plan_cache_capacity=capacity,
|
|
214
|
+
clock=clock,
|
|
215
|
+
lifecycle_provider=lifecycle_provider,
|
|
216
|
+
)
|
|
217
|
+
except BaseException:
|
|
218
|
+
runtime.close()
|
|
219
|
+
raise
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
connect = Database.connect
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Final
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"SnapshotConnectionError",
|
|
7
|
+
"SnapshotMaterializationError",
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SnapshotConnectionError(ValueError):
|
|
12
|
+
"""A modeled read was asked of a Database over a model that names no class.
|
|
13
|
+
|
|
14
|
+
A Snapshot answers Entity Class instances, so serving one needs a
|
|
15
|
+
class-backed :class:`~parallax.core.DomainModel` — one that composed Entity
|
|
16
|
+
Classes and therefore holds the index deciding which class a returned row
|
|
17
|
+
instantiates. Both connection doors refuse a value that is no Domain Model
|
|
18
|
+
at all, before the adapter is touched; a descriptor-backed model connects
|
|
19
|
+
and is refused here instead, at the read it cannot serve and still before
|
|
20
|
+
any SQL.
|
|
21
|
+
|
|
22
|
+
The refusal is about materialization capability and never about identity or
|
|
23
|
+
ownership: any class-backed model serves, however many other Databases
|
|
24
|
+
already serve it. :data:`code` and the message are its whole public state.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
code: Final[str] = "snapshot-class-backed-model-required"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class SnapshotMaterializationError(RuntimeError):
|
|
31
|
+
"""Building the Entity graph failed after the read itself had succeeded.
|
|
32
|
+
|
|
33
|
+
Raised exactly once, at the materialization boundary, for a graph-construction
|
|
34
|
+
refusal, or a failure answering the node-indexed graph or its lifecycle
|
|
35
|
+
states. The original exception is the ``__cause__`` and is also carried as
|
|
36
|
+
:attr:`cause`, so the defect stays diagnosable while callers branch on one
|
|
37
|
+
stable code.
|
|
38
|
+
|
|
39
|
+
Everything upstream keeps its own classification: query, capability,
|
|
40
|
+
transaction, adapter, SQL, and neutral-decoding failures are never re-wrapped
|
|
41
|
+
here, because none of them is a failure to build a graph. No partial graph and
|
|
42
|
+
no Snapshot is published when this raises.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
code: Final[str] = "snapshot-materialization-failed"
|
|
46
|
+
|
|
47
|
+
def __init__(self, message: str, *, cause: BaseException) -> None:
|
|
48
|
+
super().__init__(message)
|
|
49
|
+
self.cause = cause
|