pulse-framework 0.1.42__py3-none-any.whl → 0.1.43__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.
- pulse/__init__.py +12 -3
- pulse/decorators.py +8 -172
- pulse/helpers.py +39 -23
- pulse/queries/client.py +462 -0
- pulse/queries/common.py +28 -0
- pulse/queries/effect.py +39 -0
- pulse/queries/infinite_query.py +1157 -0
- pulse/queries/mutation.py +47 -0
- pulse/queries/query.py +560 -53
- pulse/queries/store.py +81 -18
- pulse/reactive.py +95 -20
- pulse/reactive_extensions.py +19 -7
- pulse/state.py +5 -0
- {pulse_framework-0.1.42.dist-info → pulse_framework-0.1.43.dist-info}/METADATA +1 -1
- {pulse_framework-0.1.42.dist-info → pulse_framework-0.1.43.dist-info}/RECORD +17 -15
- pulse/queries/query_observer.py +0 -365
- {pulse_framework-0.1.42.dist-info → pulse_framework-0.1.43.dist-info}/WHEEL +0 -0
- {pulse_framework-0.1.42.dist-info → pulse_framework-0.1.43.dist-info}/entry_points.txt +0 -0
pulse/queries/mutation.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import inspect
|
|
1
2
|
from collections.abc import Awaitable, Callable
|
|
2
3
|
from typing import (
|
|
3
4
|
Any,
|
|
@@ -5,6 +6,7 @@ from typing import (
|
|
|
5
6
|
Generic,
|
|
6
7
|
ParamSpec,
|
|
7
8
|
TypeVar,
|
|
9
|
+
overload,
|
|
8
10
|
override,
|
|
9
11
|
)
|
|
10
12
|
|
|
@@ -140,3 +142,48 @@ class MutationProperty(Generic[T, TState, P], InitializableProperty):
|
|
|
140
142
|
def initialize(self, state: State, name: str) -> MutationResult[T, P]:
|
|
141
143
|
# For compatibility with InitializableProperty, but mutations don't need special initialization
|
|
142
144
|
return self.__get__(state, state.__class__)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
@overload
|
|
148
|
+
def mutation(
|
|
149
|
+
fn: Callable[Concatenate[TState, P], Awaitable[T]],
|
|
150
|
+
*,
|
|
151
|
+
on_success: OnSuccessFn[TState, T] | None = None,
|
|
152
|
+
on_error: OnErrorFn[TState] | None = None,
|
|
153
|
+
) -> MutationProperty[T, TState, P]: ...
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
@overload
|
|
157
|
+
def mutation(
|
|
158
|
+
fn: None = None,
|
|
159
|
+
*,
|
|
160
|
+
on_success: OnSuccessFn[TState, T] | None = None,
|
|
161
|
+
on_error: OnErrorFn[TState] | None = None,
|
|
162
|
+
) -> Callable[
|
|
163
|
+
[Callable[Concatenate[TState, P], Awaitable[T]]], MutationProperty[T, TState, P]
|
|
164
|
+
]: ...
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def mutation(
|
|
168
|
+
fn: Callable[Concatenate[TState, P], Awaitable[T]] | None = None,
|
|
169
|
+
*,
|
|
170
|
+
on_success: OnSuccessFn[TState, T] | None = None,
|
|
171
|
+
on_error: OnErrorFn[TState] | None = None,
|
|
172
|
+
):
|
|
173
|
+
def decorator(func: Callable[Concatenate[TState, P], Awaitable[T]], /):
|
|
174
|
+
sig = inspect.signature(func)
|
|
175
|
+
params = list(sig.parameters.values())
|
|
176
|
+
|
|
177
|
+
if len(params) == 0 or params[0].name != "self":
|
|
178
|
+
raise TypeError("@mutation method must have 'self' as first argument")
|
|
179
|
+
|
|
180
|
+
return MutationProperty(
|
|
181
|
+
func.__name__,
|
|
182
|
+
func,
|
|
183
|
+
on_success=on_success,
|
|
184
|
+
on_error=on_error,
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
if fn:
|
|
188
|
+
return decorator(fn)
|
|
189
|
+
return decorator
|