apexdevkit 2.3.2__py3-none-any.whl → 2.4.1__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.
- apexdevkit/repository/sql/connector.py +1 -0
- {apexdevkit-2.3.2.dist-info → apexdevkit-2.4.1.dist-info}/METADATA +3 -4
- {apexdevkit-2.3.2.dist-info → apexdevkit-2.4.1.dist-info}/RECORD +5 -10
- apexdevkit/sync/__init__.py +0 -19
- apexdevkit/sync/observer.py +0 -92
- apexdevkit/sync/source.py +0 -136
- apexdevkit/sync/sync.py +0 -167
- apexdevkit/sync/target.py +0 -89
- {apexdevkit-2.3.2.dist-info → apexdevkit-2.4.1.dist-info}/WHEEL +0 -0
- {apexdevkit-2.3.2.dist-info → apexdevkit-2.4.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: apexdevkit
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.1
|
|
4
4
|
Summary: Apex Development Tools for python.
|
|
5
5
|
License-File: LICENSE
|
|
6
6
|
Author: Apex Dev
|
|
7
7
|
Author-email: dev@apex.ge
|
|
8
|
-
Requires-Python: >=3.
|
|
8
|
+
Requires-Python: >=3.13,<4
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
11
10
|
Classifier: Programming Language :: Python :: 3.13
|
|
12
11
|
Classifier: Programming Language :: Python :: 3.14
|
|
13
12
|
Classifier: Programming Language :: Python :: 3.15
|
|
14
13
|
Requires-Dist: fastapi
|
|
15
14
|
Requires-Dist: pydantic
|
|
16
15
|
Requires-Dist: pymssql (==2.*)
|
|
17
|
-
Requires-Dist: pypebbles (==0.
|
|
16
|
+
Requires-Dist: pypebbles (==0.5.*)
|
|
18
17
|
Requires-Dist: python-dotenv
|
|
19
18
|
Requires-Dist: sentry-sdk[fastapi]
|
|
20
19
|
Requires-Dist: uvicorn
|
|
@@ -29,7 +29,7 @@ apexdevkit/repository/in_memory/mixin.py,sha256=aFr5Cg0B_g_i5ZTZ1fzlunfG-7W3MV0_
|
|
|
29
29
|
apexdevkit/repository/in_memory/repository.py,sha256=-xLqrQN-o--doDVEKhqyUcVZfgp6_8_fjnxGGUCUsbY,2206
|
|
30
30
|
apexdevkit/repository/in_memory/store.py,sha256=K7vw3w4yctLGbrknGT16b3CZnloZZIHSFD2AkUIv_80,1260
|
|
31
31
|
apexdevkit/repository/sql/__init__.py,sha256=xftLpLVlXvBuMIaaWHNT7M7rmReehgHysQwrfok8-ig,267
|
|
32
|
-
apexdevkit/repository/sql/connector.py,sha256=
|
|
32
|
+
apexdevkit/repository/sql/connector.py,sha256=0DacXgPdjR405YiKLXSaHDsLnf5TZmAOo58CgdvuSbM,2473
|
|
33
33
|
apexdevkit/repository/sql/field.py,sha256=IgzHXIHyi6zNDzbmcT1rc7ZXUCp8jfwlCOvtCtcSejA,9221
|
|
34
34
|
apexdevkit/repository/sql/mssql/__init__.py,sha256=dIMytBRcoMliByJynZ0UuVG3R1nXw6Dpg_gUckasLlM,200
|
|
35
35
|
apexdevkit/repository/sql/mssql/repository.py,sha256=_ieZ_Hfi46KjOhVnc81n68cPYC-o4RAe0pSS4_CxP1w,2493
|
|
@@ -38,13 +38,8 @@ apexdevkit/repository/sql/sqlite/__init__.py,sha256=dG08No5TFPL4P2ymZkVBgDxxBq-U
|
|
|
38
38
|
apexdevkit/repository/sql/sqlite/repository.py,sha256=goMCJle7U0-Fa9QuhpvtBiDbIW3-n6ootPxvz6fe20w,2176
|
|
39
39
|
apexdevkit/repository/sql/sqlite/table.py,sha256=iVMDAbeUVjcktSsl1STbNtWZgtITFU3TFIYdNiipweQ,7537
|
|
40
40
|
apexdevkit/server.py,sha256=s0ntyKD02p3ee5I_4ikuk9amCrUuK5hTUcNSbjvx27w,4376
|
|
41
|
-
apexdevkit/sync/__init__.py,sha256=ftZC5YGnE74tee1PTUvKbaYme1xr52ez5ZCEU6FozWw,478
|
|
42
|
-
apexdevkit/sync/observer.py,sha256=UgslyGBRovaiaAWbM9TssFz9n3ARbSEx0x4cMZ7kWKw,2453
|
|
43
|
-
apexdevkit/sync/source.py,sha256=S0J8XofxbJjptShZlwZvXxU61CopJUflXe1eQ9FVeec,3836
|
|
44
|
-
apexdevkit/sync/sync.py,sha256=TWxtqO_wZyDy6D8reAq439p6QF17fn2n8zthjJlOCfs,4822
|
|
45
|
-
apexdevkit/sync/target.py,sha256=SVApnIrG_o9uf0s4iFiDOZl4ch8Kv9s3PQFM09ItttY,2653
|
|
46
41
|
apexdevkit/testing.py,sha256=7Xc0HMWgkj8vjdBI7KS86Uknhlbaitw6U20sI_7IblQ,4505
|
|
47
|
-
apexdevkit-2.
|
|
48
|
-
apexdevkit-2.
|
|
49
|
-
apexdevkit-2.
|
|
50
|
-
apexdevkit-2.
|
|
42
|
+
apexdevkit-2.4.1.dist-info/METADATA,sha256=zjosXuWhCgYBtAGeBHLSYJz46049KOi_sysSkbq4ZQE,645
|
|
43
|
+
apexdevkit-2.4.1.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
|
|
44
|
+
apexdevkit-2.4.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
45
|
+
apexdevkit-2.4.1.dist-info/RECORD,,
|
apexdevkit/sync/__init__.py
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
from .observer import SyncObserver
|
|
2
|
-
from .source import EmptySource, Source, SourceDecorator, SourceFailing, SourcePreSet
|
|
3
|
-
from .sync import Sync, SyncProbe
|
|
4
|
-
from .target import NoTarget, Target, TargetDecorator, TargetFailing
|
|
5
|
-
|
|
6
|
-
__all__ = [
|
|
7
|
-
"EmptySource",
|
|
8
|
-
"NoTarget",
|
|
9
|
-
"Source",
|
|
10
|
-
"SourceDecorator",
|
|
11
|
-
"SourceFailing",
|
|
12
|
-
"SourcePreSet",
|
|
13
|
-
"Sync",
|
|
14
|
-
"SyncObserver",
|
|
15
|
-
"SyncProbe",
|
|
16
|
-
"Target",
|
|
17
|
-
"TargetDecorator",
|
|
18
|
-
"TargetFailing",
|
|
19
|
-
]
|
apexdevkit/sync/observer.py
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from dataclasses import dataclass, field
|
|
4
|
-
from typing import TYPE_CHECKING, Protocol, Self
|
|
5
|
-
|
|
6
|
-
if TYPE_CHECKING:
|
|
7
|
-
from collections.abc import Callable
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@dataclass(frozen=True)
|
|
11
|
-
class ObservableSync:
|
|
12
|
-
observers: list[SyncObserver] = field(default_factory=list)
|
|
13
|
-
|
|
14
|
-
def attach(self, observer: SyncObserver, *, when: bool = True) -> Self:
|
|
15
|
-
if when:
|
|
16
|
-
self.observers.append(observer)
|
|
17
|
-
|
|
18
|
-
return self
|
|
19
|
-
|
|
20
|
-
def before_prune(self, n_items: int) -> None:
|
|
21
|
-
for observer in self.observers:
|
|
22
|
-
observer.before_prune(n_items)
|
|
23
|
-
|
|
24
|
-
def after_prune(self, n_items: int) -> None:
|
|
25
|
-
_ = n_items
|
|
26
|
-
|
|
27
|
-
for observer in self.observers:
|
|
28
|
-
observer.after_prune()
|
|
29
|
-
|
|
30
|
-
def before_load(self, n_items: int) -> None:
|
|
31
|
-
for observer in self.observers:
|
|
32
|
-
observer.before_load(n_items)
|
|
33
|
-
|
|
34
|
-
def after_load(self, n_items: int) -> None:
|
|
35
|
-
_ = n_items
|
|
36
|
-
|
|
37
|
-
for observer in self.observers:
|
|
38
|
-
observer.after_load()
|
|
39
|
-
|
|
40
|
-
def before_update(self, n_items: int) -> None:
|
|
41
|
-
for observer in self.observers:
|
|
42
|
-
observer.before_update(n_items)
|
|
43
|
-
|
|
44
|
-
def after_update(self, n_items: int) -> None:
|
|
45
|
-
_ = n_items
|
|
46
|
-
|
|
47
|
-
for observer in self.observers:
|
|
48
|
-
observer.after_update()
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
class SyncObserver(Protocol): # pragma: no cover
|
|
52
|
-
def before_prune(self, n_items: int) -> None:
|
|
53
|
-
pass
|
|
54
|
-
|
|
55
|
-
def after_prune(self) -> None:
|
|
56
|
-
pass
|
|
57
|
-
|
|
58
|
-
def before_load(self, n_items: int) -> None:
|
|
59
|
-
pass
|
|
60
|
-
|
|
61
|
-
def after_load(self) -> None:
|
|
62
|
-
pass
|
|
63
|
-
|
|
64
|
-
def before_update(self, n_items: int) -> None:
|
|
65
|
-
pass
|
|
66
|
-
|
|
67
|
-
def after_update(self) -> None:
|
|
68
|
-
pass
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
@dataclass(frozen=True)
|
|
72
|
-
class DefaultLog:
|
|
73
|
-
name: str = "items"
|
|
74
|
-
echo: Callable[[str], None] = print
|
|
75
|
-
|
|
76
|
-
def before_prune(self, n_items: int) -> None:
|
|
77
|
-
self.echo(f"Total # of absent {self.name}: {n_items}")
|
|
78
|
-
|
|
79
|
-
def after_prune(self) -> None:
|
|
80
|
-
self.echo("Pruning completed")
|
|
81
|
-
|
|
82
|
-
def before_load(self, n_items: int) -> None:
|
|
83
|
-
self.echo(f"Total # of new {self.name}: {n_items}")
|
|
84
|
-
|
|
85
|
-
def after_load(self) -> None:
|
|
86
|
-
self.echo("Loading completed")
|
|
87
|
-
|
|
88
|
-
def before_update(self, n_items: int) -> None:
|
|
89
|
-
self.echo(f"Total # of changed {self.name}: {n_items}")
|
|
90
|
-
|
|
91
|
-
def after_update(self) -> None:
|
|
92
|
-
self.echo("Updating completed")
|
apexdevkit/sync/source.py
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from dataclasses import dataclass, field
|
|
4
|
-
from typing import TYPE_CHECKING, Any, Protocol
|
|
5
|
-
|
|
6
|
-
from apexdevkit.key_fn import AttributeKey, KeyFn
|
|
7
|
-
|
|
8
|
-
if TYPE_CHECKING:
|
|
9
|
-
from collections.abc import Iterable
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class Source[T](Protocol): # pragma: no cover
|
|
13
|
-
def absent(self) -> Iterable[T]:
|
|
14
|
-
pass
|
|
15
|
-
|
|
16
|
-
def new(self) -> Iterable[T]:
|
|
17
|
-
pass
|
|
18
|
-
|
|
19
|
-
def updates(self) -> Iterable[T]:
|
|
20
|
-
pass
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@dataclass(frozen=True)
|
|
24
|
-
class EmptySource[T]: # pragma: no cover
|
|
25
|
-
def absent(self) -> Iterable[T]:
|
|
26
|
-
return []
|
|
27
|
-
|
|
28
|
-
def new(self) -> Iterable[T]:
|
|
29
|
-
return []
|
|
30
|
-
|
|
31
|
-
def updates(self) -> Iterable[T]:
|
|
32
|
-
return []
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
@dataclass(frozen=True, kw_only=True)
|
|
36
|
-
class SourceDecorator[T]: # pragma: no cover
|
|
37
|
-
inner: Source[T] = field(default_factory=EmptySource)
|
|
38
|
-
|
|
39
|
-
def absent(self) -> Iterable[T]:
|
|
40
|
-
return self.inner.absent()
|
|
41
|
-
|
|
42
|
-
def new(self) -> Iterable[T]:
|
|
43
|
-
return self.inner.new()
|
|
44
|
-
|
|
45
|
-
def updates(self) -> Iterable[T]:
|
|
46
|
-
return self.inner.updates()
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
@dataclass(frozen=True, kw_only=True)
|
|
50
|
-
class SourcePreSet[T]:
|
|
51
|
-
removals: Iterable[T] = field(default_factory=list)
|
|
52
|
-
additions: Iterable[T] = field(default_factory=list)
|
|
53
|
-
changes: Iterable[T] = field(default_factory=list)
|
|
54
|
-
|
|
55
|
-
def absent(self) -> Iterable[T]:
|
|
56
|
-
return self.removals
|
|
57
|
-
|
|
58
|
-
def new(self) -> Iterable[T]:
|
|
59
|
-
return self.additions
|
|
60
|
-
|
|
61
|
-
def updates(self) -> Iterable[T]:
|
|
62
|
-
return self.changes
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
class SourceFailing[T]: # pragma: no cover
|
|
66
|
-
@staticmethod
|
|
67
|
-
def on_everything(using: Source[T] | None = None) -> Source[T]:
|
|
68
|
-
return SourceFailing.on_absent(
|
|
69
|
-
using=SourceFailing.on_new(
|
|
70
|
-
using=SourceFailing.on_update(
|
|
71
|
-
using=using or EmptySource(),
|
|
72
|
-
),
|
|
73
|
-
),
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
@staticmethod
|
|
77
|
-
def on_absent(using: Source[T] | None = None) -> Source[T]:
|
|
78
|
-
return _FailOnAbsent(inner=using or EmptySource())
|
|
79
|
-
|
|
80
|
-
@staticmethod
|
|
81
|
-
def on_new(using: Source[T] | None = None) -> Source[T]:
|
|
82
|
-
return _FailOnNew(inner=using or EmptySource())
|
|
83
|
-
|
|
84
|
-
@staticmethod
|
|
85
|
-
def on_update(using: Source[T] | None = None) -> Source[T]:
|
|
86
|
-
return _FailOnUpdate(inner=using or EmptySource())
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
@dataclass(frozen=True, kw_only=True)
|
|
90
|
-
class _FailOnAbsent[T](SourceDecorator[T]):
|
|
91
|
-
def absent(self) -> Iterable[T]: # pragma: no cover
|
|
92
|
-
raise RuntimeError("Should not request absent!")
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
@dataclass(frozen=True, kw_only=True)
|
|
96
|
-
class _FailOnNew[T](SourceDecorator[T]):
|
|
97
|
-
def new(self) -> Iterable[T]: # pragma: no cover
|
|
98
|
-
raise RuntimeError("Should not request new!")
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
@dataclass(frozen=True, kw_only=True)
|
|
102
|
-
class _FailOnUpdate[T](SourceDecorator[T]):
|
|
103
|
-
def updates(self) -> Iterable[T]: # pragma: no cover
|
|
104
|
-
raise RuntimeError("Should not request updates!")
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
@dataclass(frozen=True, kw_only=True)
|
|
108
|
-
class SourceDiscriminator[T]:
|
|
109
|
-
current: Iterable[T]
|
|
110
|
-
latest: Iterable[T]
|
|
111
|
-
|
|
112
|
-
key_fn: KeyFn | None = None
|
|
113
|
-
|
|
114
|
-
def absent(self) -> Iterable[T]:
|
|
115
|
-
index = {self.key_of(item) for item in self.latest}
|
|
116
|
-
|
|
117
|
-
return [item for item in self.current if self.key_of(item) not in index]
|
|
118
|
-
|
|
119
|
-
def new(self) -> Iterable[T]:
|
|
120
|
-
index = {self.key_of(item) for item in self.current}
|
|
121
|
-
|
|
122
|
-
return [item for item in self.latest if self.key_of(item) not in index]
|
|
123
|
-
|
|
124
|
-
def updates(self) -> Iterable[T]:
|
|
125
|
-
index = {self.key_of(item) for item in self.current}
|
|
126
|
-
|
|
127
|
-
return [
|
|
128
|
-
item
|
|
129
|
-
for item in set(self.latest).difference(self.current)
|
|
130
|
-
if self.key_of(item) in index
|
|
131
|
-
]
|
|
132
|
-
|
|
133
|
-
def key_of(self, item: Any) -> str:
|
|
134
|
-
key_fn = self.key_fn or AttributeKey("id")
|
|
135
|
-
|
|
136
|
-
return key_fn(item)
|
apexdevkit/sync/sync.py
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from dataclasses import dataclass, field, replace
|
|
4
|
-
from typing import TYPE_CHECKING, Any, Self, TypeVar
|
|
5
|
-
|
|
6
|
-
from apexdevkit.key_fn import AttributeKey, KeyFn
|
|
7
|
-
|
|
8
|
-
from .observer import DefaultLog, ObservableSync
|
|
9
|
-
from .source import EmptySource, Source, SourceDiscriminator, SourcePreSet
|
|
10
|
-
from .target import IterableTarget, NoTarget, Target
|
|
11
|
-
|
|
12
|
-
if TYPE_CHECKING:
|
|
13
|
-
from collections.abc import Callable, Collection, Iterable
|
|
14
|
-
|
|
15
|
-
T = TypeVar("T")
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@dataclass(frozen=True, kw_only=True)
|
|
19
|
-
class Sync[T](ObservableSync):
|
|
20
|
-
source: Source[T] = field(default_factory=EmptySource)
|
|
21
|
-
target: Target[T] = field(default_factory=NoTarget)
|
|
22
|
-
|
|
23
|
-
dry_run: bool = False
|
|
24
|
-
|
|
25
|
-
def purge(self) -> _Purge[T]:
|
|
26
|
-
return _Purge[T](sync=self)
|
|
27
|
-
|
|
28
|
-
def discriminate(self, latest: Iterable[T]) -> _Discriminate[T]:
|
|
29
|
-
return _Discriminate[T](sync=self, latest=latest)
|
|
30
|
-
|
|
31
|
-
def and_target(self, value: Target[T]) -> Sync[T]:
|
|
32
|
-
return self.with_target(value)
|
|
33
|
-
|
|
34
|
-
def with_target(self, value: Target[T]) -> Sync[T]:
|
|
35
|
-
return replace(self, target=value)
|
|
36
|
-
|
|
37
|
-
def and_source(self, value: Source[T]) -> Sync[T]:
|
|
38
|
-
return self.with_source(value) # pragma: no cover
|
|
39
|
-
|
|
40
|
-
def with_source(self, value: Source[T]) -> Sync[T]:
|
|
41
|
-
return replace(self, source=value)
|
|
42
|
-
|
|
43
|
-
def with_log(self, using: Callable[[str], None], named: str = "items") -> Self:
|
|
44
|
-
return self.attach(DefaultLog(name=named, echo=using))
|
|
45
|
-
|
|
46
|
-
def dry(self, *, when: bool = True) -> Sync[T]:
|
|
47
|
-
return replace(self, dry_run=when)
|
|
48
|
-
|
|
49
|
-
def run(
|
|
50
|
-
self,
|
|
51
|
-
*,
|
|
52
|
-
prune: bool = True,
|
|
53
|
-
load: bool = True,
|
|
54
|
-
update: bool = True,
|
|
55
|
-
) -> None:
|
|
56
|
-
if prune:
|
|
57
|
-
self.prune()
|
|
58
|
-
|
|
59
|
-
if load:
|
|
60
|
-
self.load()
|
|
61
|
-
|
|
62
|
-
if update:
|
|
63
|
-
self.update()
|
|
64
|
-
|
|
65
|
-
def prune(self) -> None:
|
|
66
|
-
(
|
|
67
|
-
SyncProbe(source=set(self.source.absent()))
|
|
68
|
-
.disable(when=self.dry_run)
|
|
69
|
-
.notify(using=self.before_prune)
|
|
70
|
-
.send(using=self.target.prune)
|
|
71
|
-
.notify(using=self.after_prune)
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
def load(self) -> None:
|
|
75
|
-
(
|
|
76
|
-
SyncProbe(source=set(self.source.new()))
|
|
77
|
-
.disable(when=self.dry_run)
|
|
78
|
-
.notify(using=self.before_load)
|
|
79
|
-
.send(using=self.target.load)
|
|
80
|
-
.notify(using=self.after_load)
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
def update(self) -> None:
|
|
84
|
-
(
|
|
85
|
-
SyncProbe(source=set(self.source.updates()))
|
|
86
|
-
.disable(when=self.dry_run)
|
|
87
|
-
.notify(using=self.before_update)
|
|
88
|
-
.send(using=self.target.renew)
|
|
89
|
-
.notify(using=self.after_update)
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
@dataclass(frozen=True, kw_only=True)
|
|
94
|
-
class _Purge[T]:
|
|
95
|
-
sync: Sync[T]
|
|
96
|
-
|
|
97
|
-
def target(self, value: IterableTarget[T]) -> _Purge[T]:
|
|
98
|
-
return _Purge[T](
|
|
99
|
-
sync=replace(
|
|
100
|
-
self.sync,
|
|
101
|
-
target=value,
|
|
102
|
-
source=SourcePreSet[T](removals=list(value)),
|
|
103
|
-
)
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
def __call__(self) -> None:
|
|
107
|
-
self.run() # pragma: no cover
|
|
108
|
-
|
|
109
|
-
def run(self) -> None:
|
|
110
|
-
self.sync.prune()
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
@dataclass
|
|
114
|
-
class _Discriminate[T]:
|
|
115
|
-
sync: Sync[T]
|
|
116
|
-
latest: Iterable[T]
|
|
117
|
-
|
|
118
|
-
current: Iterable[T] = field(default_factory=list)
|
|
119
|
-
|
|
120
|
-
def against(self, target: IterableTarget[T]) -> _Discriminate[T]:
|
|
121
|
-
return self.target(target).and_current(list(target))
|
|
122
|
-
|
|
123
|
-
def target(self, value: Target[T]) -> _Discriminate[T]:
|
|
124
|
-
return replace(self, sync=self.sync.with_target(value))
|
|
125
|
-
|
|
126
|
-
def and_current(self, value: Iterable[T]) -> _Discriminate[T]:
|
|
127
|
-
return replace(self, current=value)
|
|
128
|
-
|
|
129
|
-
def default(self) -> Sync[T]:
|
|
130
|
-
return self.using_attribute(name="id")
|
|
131
|
-
|
|
132
|
-
def using_attribute(self, name: str) -> Sync[T]:
|
|
133
|
-
return self.using(key_fn=AttributeKey(name))
|
|
134
|
-
|
|
135
|
-
def using(self, key_fn: KeyFn) -> Sync[T]:
|
|
136
|
-
return self.sync.with_source(
|
|
137
|
-
SourceDiscriminator(
|
|
138
|
-
current=self.current,
|
|
139
|
-
latest=self.latest,
|
|
140
|
-
key_fn=key_fn,
|
|
141
|
-
)
|
|
142
|
-
)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
@dataclass(frozen=True, kw_only=True)
|
|
146
|
-
class SyncProbe:
|
|
147
|
-
source: Collection[Any]
|
|
148
|
-
|
|
149
|
-
is_enabled: bool = True
|
|
150
|
-
|
|
151
|
-
def disable(self, *, when: bool) -> SyncProbe:
|
|
152
|
-
return SyncProbe(source=self.source, is_enabled=not when)
|
|
153
|
-
|
|
154
|
-
def notify(self, using: Callable[[int], None]) -> SyncProbe:
|
|
155
|
-
using(len(self.source))
|
|
156
|
-
|
|
157
|
-
return self
|
|
158
|
-
|
|
159
|
-
def send(self, using: Callable[[Iterable[Any]], Iterable[Any] | None]) -> SyncProbe:
|
|
160
|
-
result = None
|
|
161
|
-
if self.is_enabled and len(self.source) > 0:
|
|
162
|
-
result = using(self.source)
|
|
163
|
-
|
|
164
|
-
if result:
|
|
165
|
-
list(result)
|
|
166
|
-
|
|
167
|
-
return self
|
apexdevkit/sync/target.py
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from collections.abc import Iterable
|
|
4
|
-
from dataclasses import dataclass, field
|
|
5
|
-
from typing import Protocol, TypeVar
|
|
6
|
-
|
|
7
|
-
T = TypeVar("T")
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class Target(Protocol[T]): # pragma: no cover
|
|
11
|
-
def prune(self, source: Iterable[T]) -> Iterable[T] | None:
|
|
12
|
-
pass
|
|
13
|
-
|
|
14
|
-
def load(self, source: Iterable[T]) -> Iterable[T] | None:
|
|
15
|
-
pass
|
|
16
|
-
|
|
17
|
-
def renew(self, source: Iterable[T]) -> Iterable[T] | None:
|
|
18
|
-
pass
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class IterableTarget(Target[T], Iterable[T], Protocol[T]):
|
|
22
|
-
pass
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class NoTarget[T]: # pragma: no cover
|
|
26
|
-
def prune(self, source: Iterable[T]) -> Iterable[T] | None:
|
|
27
|
-
pass
|
|
28
|
-
|
|
29
|
-
def load(self, source: Iterable[T]) -> Iterable[T] | None:
|
|
30
|
-
pass
|
|
31
|
-
|
|
32
|
-
def renew(self, source: Iterable[T]) -> Iterable[T] | None:
|
|
33
|
-
pass
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
@dataclass(frozen=True, kw_only=True)
|
|
37
|
-
class TargetDecorator[T]:
|
|
38
|
-
inner: Target[T] = field(default_factory=NoTarget)
|
|
39
|
-
|
|
40
|
-
def prune(self, source: Iterable[T]) -> Iterable[T] | None:
|
|
41
|
-
return self.inner.prune(source)
|
|
42
|
-
|
|
43
|
-
def load(self, source: Iterable[T]) -> Iterable[T] | None:
|
|
44
|
-
return self.inner.load(source)
|
|
45
|
-
|
|
46
|
-
def renew(self, source: Iterable[T]) -> Iterable[T] | None:
|
|
47
|
-
return self.inner.renew(source)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
class TargetFailing[T]:
|
|
51
|
-
@staticmethod
|
|
52
|
-
def on_everything(using: Target[T] | None = None) -> Target[T]:
|
|
53
|
-
return TargetFailing.on_prune(
|
|
54
|
-
using=TargetFailing.on_load(
|
|
55
|
-
using=TargetFailing.on_update(
|
|
56
|
-
using=using or NoTarget(),
|
|
57
|
-
),
|
|
58
|
-
),
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
@staticmethod
|
|
62
|
-
def on_prune(using: Target[T] | None = None) -> Target[T]:
|
|
63
|
-
return _FailOnPrune(inner=using or NoTarget())
|
|
64
|
-
|
|
65
|
-
@staticmethod
|
|
66
|
-
def on_load(using: Target[T] | None = None) -> Target[T]:
|
|
67
|
-
return _FailOnLoad(inner=using or NoTarget())
|
|
68
|
-
|
|
69
|
-
@staticmethod
|
|
70
|
-
def on_update(using: Target[T] | None = None) -> Target[T]:
|
|
71
|
-
return _FailOnUpdate(inner=using or NoTarget())
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
@dataclass(frozen=True, kw_only=True)
|
|
75
|
-
class _FailOnPrune(TargetDecorator[T]):
|
|
76
|
-
def prune(self, source: Iterable[T]) -> Iterable[T] | None: # pragma: no cover
|
|
77
|
-
raise RuntimeError(source)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
@dataclass(frozen=True, kw_only=True)
|
|
81
|
-
class _FailOnLoad(TargetDecorator[T]):
|
|
82
|
-
def load(self, source: Iterable[T]) -> Iterable[T] | None: # pragma: no cover
|
|
83
|
-
raise RuntimeError(source)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
@dataclass(frozen=True, kw_only=True)
|
|
87
|
-
class _FailOnUpdate(TargetDecorator[T]):
|
|
88
|
-
def renew(self, source: Iterable[T]) -> Iterable[T] | None: # pragma: no cover
|
|
89
|
-
raise RuntimeError(source)
|
|
File without changes
|
|
File without changes
|