type-bridge 2.2.6__tar.gz → 2.3.1__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.
- {type_bridge-2.2.6 → type_bridge-2.3.1}/.gitignore +0 -1
- {type_bridge-2.2.6 → type_bridge-2.3.1}/PKG-INFO +12 -8
- {type_bridge-2.2.6 → type_bridge-2.3.1}/README.md +7 -3
- {type_bridge-2.2.6 → type_bridge-2.3.1}/pyproject.toml +11 -11
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/__init__.py +10 -1
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/_runtime_projection.py +30 -1
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/attribute/base.py +2 -58
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/attribute/flags.py +12 -23
- type_bridge-2.3.1/type_bridge/crud/formatting.py +58 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/crud/patterns.py +2 -2
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/crud/role_players.py +38 -21
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/crud/rust_manager.py +27 -16
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/crud/types.py +11 -2
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/expressions/base.py +2 -6
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/expressions/functions.py +41 -26
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/expressions/utils.py +6 -1
- type_bridge-2.3.1/type_bridge/failure.py +32 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/_operations.py +75 -320
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/utils.py +8 -6
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/models/base.py +3 -13
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/models/entity.py +7 -66
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/models/relation.py +8 -84
- type_bridge-2.3.1/type_bridge/plan.py +552 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/query/__init__.py +24 -42
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/query/ast.py +21 -0
- type_bridge-2.3.1/type_bridge/query/compiler.py +417 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/query/parser.py +3 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/session.py +35 -4
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/typedb_driver.py +7 -7
- type_bridge-2.3.1/type_bridge/typeql/_schema.py +39 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/typeql/annotations.py +16 -27
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/version.py +2 -2
- type_bridge-2.2.6/type_bridge/crud/formatting.py +0 -114
- type_bridge-2.2.6/type_bridge/query/compiler.py +0 -590
- type_bridge-2.2.6/type_bridge/typed/__init__.py +0 -52
- type_bridge-2.2.6/type_bridge/typed/_remote_terminal.py +0 -198
- type_bridge-2.2.6/type_bridge/typed/_terminal.py +0 -221
- type_bridge-2.2.6/type_bridge/typed/page.py +0 -47
- type_bridge-2.2.6/type_bridge/typed/query.py +0 -1849
- type_bridge-2.2.6/type_bridge/typed/references.py +0 -523
- type_bridge-2.2.6/type_bridge/typed/remote_limits.py +0 -26
- type_bridge-2.2.6/type_bridge/typed/remote_query.py +0 -1648
- type_bridge-2.2.6/type_bridge/typed/remote_session.py +0 -354
- type_bridge-2.2.6/type_bridge/typed/results.py +0 -464
- type_bridge-2.2.6/type_bridge/typed/session.py +0 -608
- {type_bridge-2.2.6 → type_bridge-2.3.1}/LICENSE +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/_backend.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/_rust.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/_rust_runtime.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/attribute/__init__.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/attribute/boolean.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/attribute/date.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/attribute/datetime.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/attribute/datetimetz.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/attribute/decimal.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/attribute/double.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/attribute/duration.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/attribute/integer.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/attribute/numeric.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/attribute/string.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/coercion.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/crud/__init__.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/crud/aggregates.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/crud/exceptions.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/crud/has_lookup.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/crud/hooks.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/crud/lookup.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/crud/role_lookup.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/crud/strategies.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/crud/typedb_manager.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/crud/utils.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/expressions/__init__.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/expressions/aggregate.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/expressions/arithmetic.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/expressions/boolean.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/expressions/builtin.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/expressions/comparison.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/expressions/iid.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/expressions/role_player.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/expressions/string.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/fields/__init__.py +0 -0
- /type_bridge-2.2.6/type_bridge/typed/_descriptors.py → /type_bridge-2.3.1/type_bridge/fields/_generated_descriptors.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/fields/base.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/fields/role.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/__init__.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/__main__.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/_adoption_authority.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/_adoption_import.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/_archive_base.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/_archive_imports.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/_lower.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/_ref.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/exceptions.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/introspection.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/loader.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/sidecar.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/snapshots.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/state.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/migration/state_schema.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/models/__init__.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/models/registry.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/models/role.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/models/schema_scanner.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/models/utils.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/proxy.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/py.typed +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/query_v2.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/reserved_words.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/rules.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/typeql/__init__.py +0 -0
- {type_bridge-2.2.6 → type_bridge-2.3.1}/type_bridge/validation.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: type-bridge
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3.1
|
|
4
4
|
Summary: Typed Python, TypeScript, Rust, and C application tooling for TypeDB
|
|
5
5
|
Project-URL: Homepage, https://github.com/ds1sqe/type-bridge
|
|
6
6
|
Project-URL: Repository, https://github.com/ds1sqe/type-bridge
|
|
@@ -23,7 +23,7 @@ Requires-Python: <3.15,>=3.12
|
|
|
23
23
|
Requires-Dist: isodate==0.7.2
|
|
24
24
|
Requires-Dist: jinja2>=3.1.0
|
|
25
25
|
Requires-Dist: pydantic>=2.12.4
|
|
26
|
-
Requires-Dist: type-bridge-core==2.
|
|
26
|
+
Requires-Dist: type-bridge-core==2.3.1
|
|
27
27
|
Requires-Dist: typer>=0.15.0
|
|
28
28
|
Requires-Dist: typing-extensions>=4.12
|
|
29
29
|
Provides-Extra: dev
|
|
@@ -35,7 +35,7 @@ Requires-Dist: pytest-order>=1.2.0; extra == 'dev'
|
|
|
35
35
|
Requires-Dist: pytest>=9.0.1; extra == 'dev'
|
|
36
36
|
Requires-Dist: pyyaml>=6.0.3; extra == 'dev'
|
|
37
37
|
Requires-Dist: ruff==0.15.21; extra == 'dev'
|
|
38
|
-
Requires-Dist: typedb-driver==3.
|
|
38
|
+
Requires-Dist: typedb-driver==3.14.0; (python_version >= '3.14') and extra == 'dev'
|
|
39
39
|
Requires-Dist: typedb-driver~=3.11.5; (python_version < '3.14') and extra == 'dev'
|
|
40
40
|
Provides-Extra: docs
|
|
41
41
|
Requires-Dist: mkdocs-gen-files>=0.5; extra == 'docs'
|
|
@@ -45,8 +45,8 @@ Requires-Dist: mkdocs-section-index>=0.3; extra == 'docs'
|
|
|
45
45
|
Requires-Dist: mkdocs>=1.6; extra == 'docs'
|
|
46
46
|
Requires-Dist: mkdocstrings[python]>=0.27; extra == 'docs'
|
|
47
47
|
Provides-Extra: typedb-driver
|
|
48
|
-
Requires-Dist: typedb-driver<3.
|
|
49
|
-
Requires-Dist: typedb-driver
|
|
48
|
+
Requires-Dist: typedb-driver<3.15,>=3.11; (python_version < '3.14') and extra == 'typedb-driver'
|
|
49
|
+
Requires-Dist: typedb-driver<3.15,>=3.12.3; (python_version >= '3.14') and extra == 'typedb-driver'
|
|
50
50
|
Description-Content-Type: text/markdown
|
|
51
51
|
|
|
52
52
|
<p align="center">
|
|
@@ -122,10 +122,14 @@ Person.manager(db).put(ada)
|
|
|
122
122
|
people = Person.manager(db).filter(age__gte=18).all()
|
|
123
123
|
```
|
|
124
124
|
|
|
125
|
-
Use its package-local query session when a query spans types
|
|
125
|
+
Use its package-local query session when a query spans types. Query
|
|
126
|
+
terminals are coroutines; a script without an event loop wraps the session in
|
|
127
|
+
`blocking`:
|
|
126
128
|
|
|
127
129
|
```python
|
|
128
|
-
|
|
130
|
+
from type_bridge_core import blocking
|
|
131
|
+
|
|
132
|
+
session = blocking(Person.query(db))
|
|
129
133
|
person = session.exact(Person)
|
|
130
134
|
adults = (
|
|
131
135
|
session.query(person)
|
|
@@ -181,7 +185,7 @@ for generation, direct execution, transactions, and remote queries.
|
|
|
181
185
|
|
|
182
186
|
## C
|
|
183
187
|
|
|
184
|
-
TypeBridge 2.
|
|
188
|
+
TypeBridge 2.3 ships a C ABI 1.7 shared runtime and standalone CLI for
|
|
185
189
|
Ubuntu 24.04 on x86_64 GNU/Linux. Generate an application schema package from
|
|
186
190
|
Split-YAML, then link C17 or C++17 consumers with CMake or pkg-config.
|
|
187
191
|
|
|
@@ -71,10 +71,14 @@ Person.manager(db).put(ada)
|
|
|
71
71
|
people = Person.manager(db).filter(age__gte=18).all()
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
Use its package-local query session when a query spans types
|
|
74
|
+
Use its package-local query session when a query spans types. Query
|
|
75
|
+
terminals are coroutines; a script without an event loop wraps the session in
|
|
76
|
+
`blocking`:
|
|
75
77
|
|
|
76
78
|
```python
|
|
77
|
-
|
|
79
|
+
from type_bridge_core import blocking
|
|
80
|
+
|
|
81
|
+
session = blocking(Person.query(db))
|
|
78
82
|
person = session.exact(Person)
|
|
79
83
|
adults = (
|
|
80
84
|
session.query(person)
|
|
@@ -130,7 +134,7 @@ for generation, direct execution, transactions, and remote queries.
|
|
|
130
134
|
|
|
131
135
|
## C
|
|
132
136
|
|
|
133
|
-
TypeBridge 2.
|
|
137
|
+
TypeBridge 2.3 ships a C ABI 1.7 shared runtime and standalone CLI for
|
|
134
138
|
Ubuntu 24.04 on x86_64 GNU/Linux. Generate an application schema package from
|
|
135
139
|
Split-YAML, then link C17 or C++17 consumers with CMake or pkg-config.
|
|
136
140
|
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "type-bridge"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.3.1"
|
|
8
8
|
description = "Typed Python, TypeScript, Rust, and C application tooling for TypeDB"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12,<3.15"
|
|
@@ -30,7 +30,7 @@ dependencies = [
|
|
|
30
30
|
"jinja2>=3.1.0",
|
|
31
31
|
"typer>=0.15.0",
|
|
32
32
|
# The facade and native semantic engine are one release unit.
|
|
33
|
-
"type-bridge-core==2.
|
|
33
|
+
"type-bridge-core==2.3.1",
|
|
34
34
|
"typing-extensions>=4.12",
|
|
35
35
|
]
|
|
36
36
|
|
|
@@ -54,11 +54,11 @@ dev = [
|
|
|
54
54
|
# CPython 3.12 and 3.13 use the band-8 driver matching the shared 3.11.5 test
|
|
55
55
|
# server. The first native driver line supporting CPython 3.14 is band 9,
|
|
56
56
|
# so that interpreter has a dedicated native-constructor smoke; direct
|
|
57
|
-
# connections from that lane require a 3.12 server. The ORM
|
|
58
|
-
# the embedded Rust runtime and serves TypeDB 3.11
|
|
59
|
-
# supported interpreter.
|
|
57
|
+
# connections from that lane require a 3.12, 3.13 or 3.14 server. The ORM
|
|
58
|
+
# itself uses the embedded Rust runtime and serves TypeDB 3.11 through 3.14
|
|
59
|
+
# on every supported interpreter.
|
|
60
60
|
"typedb-driver~=3.11.5; python_version < '3.14'",
|
|
61
|
-
"typedb-driver==3.
|
|
61
|
+
"typedb-driver==3.14.0; python_version >= '3.14'",
|
|
62
62
|
"pytest>=9.0.1",
|
|
63
63
|
"pytest-asyncio>=1.3.0",
|
|
64
64
|
"pytest-order>=1.2.0",
|
|
@@ -80,8 +80,8 @@ docs = [
|
|
|
80
80
|
"mkdocs-section-index>=0.3",
|
|
81
81
|
]
|
|
82
82
|
typedb-driver = [
|
|
83
|
-
"typedb-driver>=3.11,<3.
|
|
84
|
-
"typedb-driver
|
|
83
|
+
"typedb-driver>=3.11,<3.15; python_version < '3.14'",
|
|
84
|
+
"typedb-driver>=3.12.3,<3.15; python_version >= '3.14'",
|
|
85
85
|
]
|
|
86
86
|
|
|
87
87
|
[tool.ty.environment]
|
|
@@ -136,10 +136,10 @@ markers = [
|
|
|
136
136
|
"integration: marks tests as integration tests (require running TypeDB)",
|
|
137
137
|
"proxy: marks tests as proxy integration tests (require proxy server + TypeDB)",
|
|
138
138
|
"unit: marks tests as unit tests (fast, no external dependencies)",
|
|
139
|
-
"
|
|
139
|
+
"slow: marks long-running live tests (run with -m slow)",
|
|
140
140
|
]
|
|
141
|
-
# By default, run only unit tests (exclude integration
|
|
142
|
-
addopts = "-m 'not integration and not
|
|
141
|
+
# By default, run only unit tests (exclude integration and proxy tests)
|
|
142
|
+
addopts = "-m 'not integration and not proxy'"
|
|
143
143
|
|
|
144
144
|
[tool.coverage.run]
|
|
145
145
|
source = ["type_bridge"]
|
|
@@ -4,6 +4,8 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from typing import TYPE_CHECKING, Any
|
|
6
6
|
|
|
7
|
+
from type_bridge.failure import CommitConflict, CommitOutcomeUnknown, CommitRejected, Failure
|
|
8
|
+
from type_bridge.plan import Plan, PlanBuilder
|
|
7
9
|
from type_bridge.proxy import ProxyDatabase, ProxyError
|
|
8
10
|
from type_bridge.query import Query, QueryBuilder
|
|
9
11
|
from type_bridge.session import (
|
|
@@ -24,7 +26,7 @@ if TYPE_CHECKING:
|
|
|
24
26
|
from type_bridge.migration.exceptions import SchemaConflictError, SchemaValidationError
|
|
25
27
|
from type_bridge.migration.introspection import SchemaIntrospector
|
|
26
28
|
|
|
27
|
-
__version__ = "2.
|
|
29
|
+
__version__ = "2.3.1"
|
|
28
30
|
|
|
29
31
|
|
|
30
32
|
_LAZY_EXPORTS: dict[str, tuple[str, str]] = {
|
|
@@ -58,10 +60,17 @@ def __getattr__(name: str) -> Any:
|
|
|
58
60
|
|
|
59
61
|
|
|
60
62
|
__all__ = [
|
|
63
|
+
"Failure",
|
|
64
|
+
"CommitConflict",
|
|
65
|
+
"CommitRejected",
|
|
66
|
+
"CommitOutcomeUnknown",
|
|
61
67
|
# Database and session
|
|
62
68
|
"Connection",
|
|
63
69
|
"Database",
|
|
64
70
|
"TransactionContext",
|
|
71
|
+
# Typed plans for staged transactions
|
|
72
|
+
"Plan",
|
|
73
|
+
"PlanBuilder",
|
|
65
74
|
# TypeDB driver (re-exported for convenience)
|
|
66
75
|
"Credentials",
|
|
67
76
|
"TransactionType",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
from collections.abc import Sequence
|
|
6
|
-
from typing import TYPE_CHECKING
|
|
6
|
+
from typing import TYPE_CHECKING, Any
|
|
7
7
|
|
|
8
8
|
if TYPE_CHECKING:
|
|
9
9
|
from type_bridge_core import PyProjectedModelManager, PyRuntimeProjection
|
|
@@ -103,6 +103,35 @@ def projected_query_builder_match_relation_for(
|
|
|
103
103
|
return projection.query_builder_match_relation(model, variable, role_players)
|
|
104
104
|
|
|
105
105
|
|
|
106
|
+
def _projected_query_builder_match_entity_clause_for(
|
|
107
|
+
model: type[GeneratedEntityProjection],
|
|
108
|
+
variable: str,
|
|
109
|
+
filters: dict[str, object],
|
|
110
|
+
) -> dict[str, Any]:
|
|
111
|
+
return _installed_projection_for(model)._query_builder_match_entity_clause(
|
|
112
|
+
model, variable, filters
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _projected_query_builder_insert_entity_clause_for(
|
|
117
|
+
instance: GeneratedEntityProjection,
|
|
118
|
+
variable: str,
|
|
119
|
+
) -> dict[str, Any]:
|
|
120
|
+
return _installed_projection_for(type(instance))._query_builder_insert_entity_clause(
|
|
121
|
+
instance, variable
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _projected_query_builder_match_relation_clause_for(
|
|
126
|
+
model: type[GeneratedRelationProjection],
|
|
127
|
+
variable: str,
|
|
128
|
+
role_players: dict[str, str] | None,
|
|
129
|
+
) -> dict[str, Any]:
|
|
130
|
+
return _installed_projection_for(model)._query_builder_match_relation_clause(
|
|
131
|
+
model, variable, role_players
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
|
|
106
135
|
def projected_manager_for(
|
|
107
136
|
projection: PyRuntimeProjection,
|
|
108
137
|
model: type[object],
|
|
@@ -254,65 +254,9 @@ class Attribute(ABC):
|
|
|
254
254
|
Returns:
|
|
255
255
|
TypeQL schema definition string
|
|
256
256
|
"""
|
|
257
|
-
from type_bridge.typeql.
|
|
258
|
-
format_doc_meta_annotations,
|
|
259
|
-
format_type_annotations,
|
|
260
|
-
)
|
|
261
|
-
|
|
262
|
-
attr_name = cls.get_attribute_name()
|
|
263
|
-
value_type = cls.get_value_type()
|
|
257
|
+
from type_bridge.typeql._schema import attribute_definition
|
|
264
258
|
|
|
265
|
-
|
|
266
|
-
type_annotations = format_type_annotations(
|
|
267
|
-
abstract=cls.abstract,
|
|
268
|
-
independent=cls.independent,
|
|
269
|
-
)
|
|
270
|
-
if include_doc_meta:
|
|
271
|
-
flags = getattr(cls, "flags", None)
|
|
272
|
-
type_annotations.extend(
|
|
273
|
-
format_doc_meta_annotations(
|
|
274
|
-
getattr(flags, "doc", None),
|
|
275
|
-
dict(getattr(flags, "meta", {}) or {}),
|
|
276
|
-
)
|
|
277
|
-
)
|
|
278
|
-
|
|
279
|
-
# Build definition: attribute name [@abstract] [@independent], [sub parent,] value type;
|
|
280
|
-
if type_annotations:
|
|
281
|
-
annotations_str = " ".join(type_annotations)
|
|
282
|
-
if cls._supertype:
|
|
283
|
-
definition = f"attribute {attr_name} {annotations_str}, sub {cls._supertype}, value {value_type}"
|
|
284
|
-
else:
|
|
285
|
-
definition = f"attribute {attr_name} {annotations_str}, value {value_type}"
|
|
286
|
-
elif cls._supertype:
|
|
287
|
-
definition = f"attribute {attr_name} sub {cls._supertype}, value {value_type}"
|
|
288
|
-
else:
|
|
289
|
-
definition = f"attribute {attr_name}, value {value_type}"
|
|
290
|
-
|
|
291
|
-
# Add @range annotation if range_constraint is defined (after value type)
|
|
292
|
-
range_constraint = getattr(cls, "range_constraint", None)
|
|
293
|
-
if range_constraint is not None:
|
|
294
|
-
range_min, range_max = range_constraint
|
|
295
|
-
# Format as @range(min..max), @range(min..), or @range(..max)
|
|
296
|
-
min_part = range_min if range_min is not None else ""
|
|
297
|
-
max_part = range_max if range_max is not None else ""
|
|
298
|
-
definition += f" @range({min_part}..{max_part})"
|
|
299
|
-
|
|
300
|
-
# Add @regex annotation if regex_pattern is defined (after value type)
|
|
301
|
-
# Note: Use regex_pattern (not regex) to avoid conflict with String.regex() query method
|
|
302
|
-
regex_pattern = getattr(cls, "regex_pattern", None)
|
|
303
|
-
if regex_pattern is not None and isinstance(regex_pattern, str):
|
|
304
|
-
# Escape any quotes in the pattern
|
|
305
|
-
escaped_pattern = regex_pattern.replace('"', '\\"')
|
|
306
|
-
definition += f' @regex("{escaped_pattern}")'
|
|
307
|
-
|
|
308
|
-
# Add @values annotation if allowed_values is defined (after value type)
|
|
309
|
-
allowed_values = getattr(cls, "allowed_values", None)
|
|
310
|
-
if allowed_values is not None and isinstance(allowed_values, tuple):
|
|
311
|
-
# Format as @values("a", "b", ...)
|
|
312
|
-
values_str = ", ".join(f'"{v}"' for v in allowed_values)
|
|
313
|
-
definition += f" @values({values_str})"
|
|
314
|
-
|
|
315
|
-
return definition + ";"
|
|
259
|
+
return attribute_definition(cls, include_doc_meta)
|
|
316
260
|
|
|
317
261
|
# ========================================================================
|
|
318
262
|
# Query Expression Class Methods (Type-Safe API)
|
|
@@ -296,31 +296,20 @@ class AttributeFlags:
|
|
|
296
296
|
Returns:
|
|
297
297
|
List of TypeQL annotation strings
|
|
298
298
|
"""
|
|
299
|
-
from type_bridge
|
|
300
|
-
|
|
301
|
-
|
|
299
|
+
from type_bridge import _rust_runtime
|
|
300
|
+
|
|
301
|
+
return _rust_runtime.rust_core()._render_schema_annotations(
|
|
302
|
+
{
|
|
303
|
+
"is_key": self.is_key,
|
|
304
|
+
"is_unique": self.is_unique,
|
|
305
|
+
"is_distinct": self.is_distinct,
|
|
306
|
+
"card_min": self.card_min,
|
|
307
|
+
"card_max": self.card_max,
|
|
308
|
+
"doc": self.doc,
|
|
309
|
+
"meta": self.meta,
|
|
310
|
+
}
|
|
302
311
|
)
|
|
303
312
|
|
|
304
|
-
annotations = []
|
|
305
|
-
if self.is_key:
|
|
306
|
-
annotations.append("@key")
|
|
307
|
-
if self.is_unique:
|
|
308
|
-
annotations.append("@unique")
|
|
309
|
-
if self.is_distinct:
|
|
310
|
-
annotations.append("@distinct")
|
|
311
|
-
|
|
312
|
-
# @key alone implies @card(1..1). Bare @unique does not imply a
|
|
313
|
-
# cardinality, so its independently derived/declared card must survive.
|
|
314
|
-
should_output_card = self.card_min is not None or self.card_max is not None
|
|
315
|
-
|
|
316
|
-
if should_output_card and not self.is_key:
|
|
317
|
-
card_annotation = format_card_annotation(self.card_min, self.card_max)
|
|
318
|
-
if card_annotation:
|
|
319
|
-
annotations.append(card_annotation)
|
|
320
|
-
|
|
321
|
-
annotations.extend(format_doc_meta_annotations(self.doc, self.meta))
|
|
322
|
-
return annotations
|
|
323
|
-
|
|
324
313
|
|
|
325
314
|
def Flag(*annotations: Any) -> Annotated[Any, AttributeFlags]:
|
|
326
315
|
"""Create attribute flags for Key, Unique, and Card markers.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Value formatting utilities for TypeQL."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from type_bridge_core import format_value as _rust_format_value
|
|
6
|
+
|
|
7
|
+
_USE_RUST = True
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def format_value(value: Any) -> str:
|
|
11
|
+
"""Format a Python value for TypeQL.
|
|
12
|
+
|
|
13
|
+
Handles extraction from Attribute instances and converts Python types
|
|
14
|
+
to their TypeQL literal representation.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
value: Python value to format (may be wrapped in Attribute instance)
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
TypeQL-formatted string literal
|
|
21
|
+
|
|
22
|
+
Examples:
|
|
23
|
+
>>> format_value("hello")
|
|
24
|
+
'"hello"'
|
|
25
|
+
>>> format_value(42)
|
|
26
|
+
'42'
|
|
27
|
+
>>> format_value(True)
|
|
28
|
+
'true'
|
|
29
|
+
>>> format_value(Decimal("123.45"))
|
|
30
|
+
'123.45dec'
|
|
31
|
+
"""
|
|
32
|
+
# Use Rust implementation when available for performance
|
|
33
|
+
return _rust_format_value(value)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def unwrap_attribute(value: Any) -> Any:
|
|
37
|
+
"""Extract raw value from Attribute instance.
|
|
38
|
+
|
|
39
|
+
This utility consolidates the common pattern of extracting the underlying
|
|
40
|
+
value from Attribute instances before processing.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
value: Value that may be an Attribute instance or raw value
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
The raw value (value.value if Attribute, otherwise value unchanged)
|
|
47
|
+
|
|
48
|
+
Examples:
|
|
49
|
+
>>> unwrap_attribute(Name("Alice"))
|
|
50
|
+
"Alice"
|
|
51
|
+
>>> unwrap_attribute("Alice")
|
|
52
|
+
"Alice"
|
|
53
|
+
>>> unwrap_attribute(42)
|
|
54
|
+
42
|
|
55
|
+
"""
|
|
56
|
+
if hasattr(value, "value"):
|
|
57
|
+
return value.value
|
|
58
|
+
return value
|
|
@@ -90,7 +90,7 @@ def build_entity_match_pattern(
|
|
|
90
90
|
'$e isa person, has name "Alice"'
|
|
91
91
|
"""
|
|
92
92
|
pattern = build_entity_match_ast(model_class, var, filters)
|
|
93
|
-
return QueryCompiler().
|
|
93
|
+
return QueryCompiler()._compile(pattern)
|
|
94
94
|
|
|
95
95
|
|
|
96
96
|
def build_relation_match_ast(
|
|
@@ -153,7 +153,7 @@ def build_relation_match_pattern(
|
|
|
153
153
|
'$r isa employment, (employee: $p)'
|
|
154
154
|
"""
|
|
155
155
|
pattern = build_relation_match_ast(model_class, var, role_players)
|
|
156
|
-
return QueryCompiler().
|
|
156
|
+
return QueryCompiler()._compile(pattern)
|
|
157
157
|
|
|
158
158
|
|
|
159
159
|
def normalize_role_players(
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
from collections.abc import Mapping
|
|
4
4
|
from typing import TYPE_CHECKING, Any
|
|
5
5
|
|
|
6
|
-
from type_bridge.crud.formatting import format_value
|
|
7
6
|
from type_bridge.crud.types import hydrate_attributes, wrap_attribute_value
|
|
8
7
|
|
|
9
8
|
if TYPE_CHECKING:
|
|
@@ -33,30 +32,44 @@ def build_role_player_match(var_name: str, entity: Any, entity_type_name: str) -
|
|
|
33
32
|
ValueError: If entity has neither _iid nor key attributes
|
|
34
33
|
"""
|
|
35
34
|
# Prefer IID-based matching when available (more precise and faster)
|
|
35
|
+
from type_bridge.query.ast import EntityPattern, HasConstraint, IidConstraint, LiteralValue
|
|
36
|
+
from type_bridge.query.compiler import QueryCompiler
|
|
37
|
+
|
|
38
|
+
variable = f"${var_name}"
|
|
39
|
+
compiler = QueryCompiler()
|
|
36
40
|
entity_iid = getattr(entity, "_iid", None)
|
|
37
41
|
if entity_iid:
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
return compiler._compile(
|
|
43
|
+
EntityPattern(
|
|
44
|
+
variable=variable,
|
|
45
|
+
type_name=entity_type_name,
|
|
46
|
+
constraints=[IidConstraint(iid=entity_iid)],
|
|
47
|
+
)
|
|
48
|
+
)
|
|
41
49
|
key_attrs = {
|
|
42
50
|
field_name: attr_info
|
|
43
51
|
for field_name, attr_info in entity.__class__.get_all_attributes().items()
|
|
44
52
|
if attr_info.flags.is_key
|
|
45
53
|
}
|
|
46
|
-
|
|
47
54
|
for field_name, attr_info in key_attrs.items():
|
|
48
55
|
value = getattr(entity, field_name)
|
|
49
56
|
if value is not None:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
return compiler._compile(
|
|
58
|
+
EntityPattern(
|
|
59
|
+
variable=variable,
|
|
60
|
+
type_name=entity_type_name,
|
|
61
|
+
constraints=[
|
|
62
|
+
HasConstraint(
|
|
63
|
+
attr_name=attr_info.typ.get_attribute_name(),
|
|
64
|
+
value=LiteralValue(value=value, value_type="string"),
|
|
65
|
+
)
|
|
66
|
+
],
|
|
67
|
+
)
|
|
68
|
+
)
|
|
56
69
|
raise ValueError(
|
|
57
70
|
f"Role player '{var_name}' ({entity.__class__.__name__}) cannot be identified: "
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
"no _iid set and no @key attributes defined. Either fetch the entity from the "
|
|
72
|
+
"database first (to populate _iid) or add Flag(Key) to an attribute."
|
|
60
73
|
)
|
|
61
74
|
|
|
62
75
|
|
|
@@ -102,15 +115,19 @@ def build_role_player_fetch_items(
|
|
|
102
115
|
Note: The caller must add type variable bindings to the match clause:
|
|
103
116
|
$employee isa $employee_type;
|
|
104
117
|
"""
|
|
105
|
-
|
|
118
|
+
from type_bridge.query.ast import FetchFunction, FetchItem, FetchNestedWildcard
|
|
119
|
+
from type_bridge.query.compiler import QueryCompiler
|
|
120
|
+
|
|
121
|
+
items: list[FetchItem] = []
|
|
106
122
|
for role_name, (role_var, _) in role_info.items():
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
123
|
+
items.extend(
|
|
124
|
+
[
|
|
125
|
+
FetchFunction(key=f"{role_name}_iid", func_name="iid", var=role_var),
|
|
126
|
+
FetchFunction(key=f"{role_name}_type", func_name="label", var=f"{role_var}_type"),
|
|
127
|
+
FetchNestedWildcard(key=role_name, var=role_var),
|
|
128
|
+
]
|
|
129
|
+
)
|
|
130
|
+
return QueryCompiler()._compile_fetch_items(items)
|
|
114
131
|
|
|
115
132
|
|
|
116
133
|
def group_results_by_iid(results: list[dict[str, Any]]) -> dict[str, list[dict[str, Any]]]:
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import re
|
|
6
|
+
import warnings
|
|
6
7
|
from typing import TYPE_CHECKING, Any, Never, Protocol, Self, cast
|
|
7
8
|
|
|
8
9
|
from type_bridge._rust_runtime import (
|
|
@@ -26,6 +27,13 @@ if TYPE_CHECKING:
|
|
|
26
27
|
from type_bridge.session import Connection
|
|
27
28
|
|
|
28
29
|
|
|
30
|
+
UPDATE_WITH_DEPRECATION = (
|
|
31
|
+
"update_with() is deprecated since 2.3.0 and is removed in 3.0; compute "
|
|
32
|
+
"the new value with let_() in an update plan (type_bridge.plan."
|
|
33
|
+
"PlanBuilder) and stage it in a transaction"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
29
37
|
class RustTypeDBManager[T: "TypeDBType"]:
|
|
30
38
|
"""Manager that delegates CRUD and query execution to Rust."""
|
|
31
39
|
|
|
@@ -411,10 +419,10 @@ class RustTypeDBManager[T: "TypeDBType"]:
|
|
|
411
419
|
self._hook_runner.run_post(event, self.model_class, instance)
|
|
412
420
|
|
|
413
421
|
def _clear_attributes(self, instance: T, attr_names: list[str], var: str) -> None:
|
|
422
|
+
if not attr_names:
|
|
423
|
+
return
|
|
414
424
|
iid = getattr(instance, "_iid", None)
|
|
415
|
-
if iid:
|
|
416
|
-
match_line = f"{var} isa {self.model_class.get_type_name()}, iid {iid};"
|
|
417
|
-
elif isinstance(instance, Entity):
|
|
425
|
+
if not iid and isinstance(instance, Entity):
|
|
418
426
|
filters = _key_filters_for_entity(instance)
|
|
419
427
|
expressions = _entity_filter_expressions(self.model_class, filters)
|
|
420
428
|
lowered = [
|
|
@@ -427,24 +435,16 @@ class RustTypeDBManager[T: "TypeDBType"]:
|
|
|
427
435
|
iid = rows[0].get("_iid")
|
|
428
436
|
if not iid:
|
|
429
437
|
return
|
|
430
|
-
|
|
431
|
-
elif isinstance(instance, Relation):
|
|
438
|
+
elif not iid and isinstance(instance, Relation):
|
|
432
439
|
iid = self._resolve_delete_iid(instance)
|
|
433
440
|
if not iid:
|
|
434
441
|
return
|
|
435
|
-
|
|
436
|
-
else:
|
|
442
|
+
elif not iid:
|
|
437
443
|
return
|
|
438
444
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
old_var = f"$old_attr_{index}"
|
|
443
|
-
match_parts.append(
|
|
444
|
-
f"try {{ {var} has {attr_name} {old_var}; {old_var} isa {attr_name}; }};"
|
|
445
|
-
)
|
|
446
|
-
delete_parts.append(f"try {{ {old_var} of {var}; }};")
|
|
447
|
-
query = "\n".join(match_parts) + "\ndelete\n" + "\n".join(delete_parts)
|
|
445
|
+
query = rust_core()._clear_attribute_query(
|
|
446
|
+
self.model_class.get_type_name(), iid, var, attr_names
|
|
447
|
+
)
|
|
448
448
|
_execute_write_query(self._connection, query)
|
|
449
449
|
|
|
450
450
|
|
|
@@ -569,6 +569,17 @@ class RustTypeDBQuery[T: "TypeDBType"]:
|
|
|
569
569
|
return self.count() > 0
|
|
570
570
|
|
|
571
571
|
def update_with(self, func: Any) -> list[T]:
|
|
572
|
+
"""Apply ``func`` to every matched instance and update each one.
|
|
573
|
+
|
|
574
|
+
.. deprecated:: 2.3.0
|
|
575
|
+
Removed in 3.0. Build an update plan that computes the new value
|
|
576
|
+
with ``let_()`` and stage it in a transaction.
|
|
577
|
+
"""
|
|
578
|
+
warnings.warn(
|
|
579
|
+
UPDATE_WITH_DEPRECATION,
|
|
580
|
+
DeprecationWarning,
|
|
581
|
+
stacklevel=2,
|
|
582
|
+
)
|
|
572
583
|
instances = self.execute()
|
|
573
584
|
if not instances:
|
|
574
585
|
return []
|
|
@@ -134,10 +134,19 @@ def build_metadata_fetch(var: str) -> str:
|
|
|
134
134
|
>>> build_metadata_fetch("e")
|
|
135
135
|
'fetch {\\n "_iid": iid($e), "_type": label($e)\\n}'
|
|
136
136
|
"""
|
|
137
|
+
from type_bridge.query.ast import FetchClause, FetchFunction
|
|
138
|
+
from type_bridge.query.compiler import QueryCompiler
|
|
139
|
+
|
|
137
140
|
if not var.startswith("$"):
|
|
138
141
|
var = f"${var}"
|
|
139
|
-
|
|
140
|
-
|
|
142
|
+
return QueryCompiler()._compile(
|
|
143
|
+
FetchClause(
|
|
144
|
+
items=[
|
|
145
|
+
FetchFunction(key="_iid", func_name="iid", var=var),
|
|
146
|
+
FetchFunction(key="_type", func_name="label", var=var),
|
|
147
|
+
]
|
|
148
|
+
)
|
|
149
|
+
)
|
|
141
150
|
|
|
142
151
|
|
|
143
152
|
def hydrate_attributes(
|
|
@@ -48,14 +48,10 @@ class Expression(ABC):
|
|
|
48
48
|
|
|
49
49
|
compiler = QueryCompiler()
|
|
50
50
|
patterns = self.to_ast(var)
|
|
51
|
-
#
|
|
52
|
-
# Compiler has _compile_pattern.
|
|
53
|
-
# But _compile_pattern is private.
|
|
54
|
-
# compiler.compile() takes a Clause.
|
|
55
|
-
# We can create a temporary MatchClause?
|
|
51
|
+
# Render the patterns as one match body, without the keyword.
|
|
56
52
|
from type_bridge.query.ast import MatchClause
|
|
57
53
|
|
|
58
|
-
return compiler.
|
|
54
|
+
return compiler._compile_clause_body(MatchClause(patterns=patterns))
|
|
59
55
|
|
|
60
56
|
def get_attribute_types(self) -> set[type["Attribute"]]:
|
|
61
57
|
"""Get all attribute types referenced by this expression.
|