pulse-framework 0.1.55__py3-none-any.whl → 0.1.57__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. pulse/__init__.py +5 -6
  2. pulse/app.py +144 -57
  3. pulse/channel.py +139 -7
  4. pulse/cli/cmd.py +16 -2
  5. pulse/codegen/codegen.py +43 -12
  6. pulse/component.py +104 -0
  7. pulse/components/for_.py +30 -4
  8. pulse/components/if_.py +28 -5
  9. pulse/components/react_router.py +61 -3
  10. pulse/context.py +39 -5
  11. pulse/cookies.py +108 -4
  12. pulse/decorators.py +193 -24
  13. pulse/env.py +56 -2
  14. pulse/form.py +198 -5
  15. pulse/helpers.py +7 -1
  16. pulse/hooks/core.py +135 -5
  17. pulse/hooks/effects.py +61 -77
  18. pulse/hooks/init.py +60 -1
  19. pulse/hooks/runtime.py +241 -0
  20. pulse/hooks/setup.py +77 -0
  21. pulse/hooks/stable.py +58 -1
  22. pulse/hooks/state.py +107 -20
  23. pulse/js/__init__.py +40 -24
  24. pulse/js/array.py +9 -6
  25. pulse/js/console.py +15 -12
  26. pulse/js/date.py +9 -6
  27. pulse/js/document.py +5 -2
  28. pulse/js/error.py +7 -4
  29. pulse/js/json.py +9 -6
  30. pulse/js/map.py +8 -5
  31. pulse/js/math.py +9 -6
  32. pulse/js/navigator.py +5 -2
  33. pulse/js/number.py +9 -6
  34. pulse/js/obj.py +16 -13
  35. pulse/js/object.py +9 -6
  36. pulse/js/promise.py +19 -13
  37. pulse/js/pulse.py +28 -25
  38. pulse/js/react.py +94 -55
  39. pulse/js/regexp.py +7 -4
  40. pulse/js/set.py +8 -5
  41. pulse/js/string.py +9 -6
  42. pulse/js/weakmap.py +8 -5
  43. pulse/js/weakset.py +8 -5
  44. pulse/js/window.py +6 -3
  45. pulse/messages.py +5 -0
  46. pulse/middleware.py +147 -76
  47. pulse/plugin.py +76 -5
  48. pulse/queries/client.py +186 -39
  49. pulse/queries/common.py +52 -3
  50. pulse/queries/infinite_query.py +154 -2
  51. pulse/queries/mutation.py +127 -7
  52. pulse/queries/query.py +112 -11
  53. pulse/react_component.py +66 -3
  54. pulse/reactive.py +314 -30
  55. pulse/reactive_extensions.py +106 -26
  56. pulse/render_session.py +304 -173
  57. pulse/request.py +46 -11
  58. pulse/routing.py +140 -4
  59. pulse/serializer.py +71 -0
  60. pulse/state.py +177 -9
  61. pulse/test_helpers.py +15 -0
  62. pulse/transpiler/__init__.py +0 -3
  63. pulse/transpiler/py_module.py +1 -7
  64. pulse/user_session.py +119 -18
  65. {pulse_framework-0.1.55.dist-info → pulse_framework-0.1.57.dist-info}/METADATA +5 -5
  66. pulse_framework-0.1.57.dist-info/RECORD +127 -0
  67. pulse/transpiler/react_component.py +0 -44
  68. pulse_framework-0.1.55.dist-info/RECORD +0 -127
  69. {pulse_framework-0.1.55.dist-info → pulse_framework-0.1.57.dist-info}/WHEEL +0 -0
  70. {pulse_framework-0.1.55.dist-info → pulse_framework-0.1.57.dist-info}/entry_points.txt +0 -0
pulse/js/__init__.py CHANGED
@@ -1,29 +1,45 @@
1
1
  """JavaScript module bindings for use in @javascript decorated functions (transpiler).
2
2
 
3
- Usage:
4
- # Import JS classes (for constructors and static methods):
5
- from pulse.js import Set, Number, Array, Date, Promise, Map, Error
6
- Set([1, 2, 3]) # -> new Set([1, 2, 3])
7
- Number.isFinite(42) # -> Number.isFinite(42)
8
- Array.isArray(x) # -> Array.isArray(x)
9
-
10
- # Import JS namespace objects (function-only modules):
11
- from pulse.js import Math, JSON, console, window, document, navigator
12
- Math.floor(3.7) # -> Math.floor(3.7)
13
- JSON.stringify(obj) # -> JSON.stringify(obj)
14
- console.log("hi") # -> console.log("hi")
15
-
16
- # Alternative: import namespace modules for namespace access:
17
- import pulse.js.json as JSON
18
- JSON.stringify(obj) # -> JSON.stringify(obj)
19
-
20
- # Statement functions:
21
- from pulse.js import throw
22
- throw(Error("message")) # -> throw Error("message");
23
-
24
- # Object literals (plain JS objects instead of Map):
25
- from pulse.js import obj
26
- obj(a=1, b=2) # -> { a: 1, b: 2 }
3
+ ## Usage
4
+
5
+ Import JS classes (for constructors and static methods):
6
+
7
+ ```python
8
+ from pulse.js import Set, Number, Array, Date, Promise, Map, Error
9
+ Set([1, 2, 3]) # -> new Set([1, 2, 3])
10
+ Number.isFinite(42) # -> Number.isFinite(42)
11
+ Array.isArray(x) # -> Array.isArray(x)
12
+ ```
13
+
14
+ Import JS namespace objects (function-only modules):
15
+
16
+ ```python
17
+ from pulse.js import Math, JSON, console, window, document, navigator
18
+ Math.floor(3.7) # -> Math.floor(3.7)
19
+ JSON.stringify(obj) # -> JSON.stringify(obj)
20
+ console.log("hi") # -> console.log("hi")
21
+ ```
22
+
23
+ Alternative: import namespace modules for namespace access:
24
+
25
+ ```python
26
+ import pulse.js.json as JSON
27
+ JSON.stringify(obj) # -> JSON.stringify(obj)
28
+ ```
29
+
30
+ Statement functions:
31
+
32
+ ```python
33
+ from pulse.js import throw
34
+ throw(Error("message")) # -> throw Error("message");
35
+ ```
36
+
37
+ Object literals (plain JS objects instead of Map):
38
+
39
+ ```python
40
+ from pulse.js import obj
41
+ obj(a=1, b=2) # -> { a: 1, b: 2 }
42
+ ```
27
43
  """
28
44
 
29
45
  import importlib as _importlib
pulse/js/array.py CHANGED
@@ -2,13 +2,16 @@
2
2
  JavaScript Array builtin module.
3
3
 
4
4
  Usage:
5
- from pulse.js import Array
6
- Array.isArray([1, 2, 3]) # -> Array.isArray([1, 2, 3])
7
- Array.from_([1, 2, 3]) # -> Array.from([1, 2, 3])
8
- Array(10) # -> new Array(10)
9
5
 
10
- # Or import from module directly:
11
- from pulse.js.array import Array
6
+ ```python
7
+ from pulse.js import Array
8
+ Array.isArray([1, 2, 3]) # -> Array.isArray([1, 2, 3])
9
+ Array.from_([1, 2, 3]) # -> Array.from([1, 2, 3])
10
+ Array(10) # -> new Array(10)
11
+
12
+ # Or import from module directly:
13
+ from pulse.js.array import Array
14
+ ```
12
15
  """
13
16
 
14
17
  from __future__ import annotations
pulse/js/console.py CHANGED
@@ -2,18 +2,21 @@
2
2
  JavaScript Console builtin module.
3
3
 
4
4
  Usage:
5
- import pulse.js.console as console
6
- console.log("Hello") # -> console.log("Hello")
7
- console.error("Error") # -> console.error("Error")
8
- console.assert(True, "msg") # -> console.assert(True, "msg")
9
-
10
- # Note: For 'assert' (Python keyword), use namespace import:
11
- # import pulse.js.console as console; console.assert(...)
12
- # Or use the underscore version for direct import:
13
- from pulse.js.console import log, error, warn, info, debug, assert_
14
- log("Hello") # -> console.log("Hello")
15
- error("Error") # -> console.error("Error")
16
- assert_(True, "msg") # -> console.assert(True, "msg")
5
+
6
+ ```python
7
+ import pulse.js.console as console
8
+ console.log("Hello") # -> console.log("Hello")
9
+ console.error("Error") # -> console.error("Error")
10
+ console.assert(True, "msg") # -> console.assert(True, "msg")
11
+
12
+ # Note: For 'assert' (Python keyword), use namespace import:
13
+ # import pulse.js.console as console; console.assert(...)
14
+ # Or use the underscore version for direct import:
15
+ from pulse.js.console import log, error, warn, info, debug, assert_
16
+ log("Hello") # -> console.log("Hello")
17
+ error("Error") # -> console.error("Error")
18
+ assert_(True, "msg") # -> console.assert(True, "msg")
19
+ ```
17
20
  """
18
21
 
19
22
  from typing import Any as _Any
pulse/js/date.py CHANGED
@@ -2,13 +2,16 @@
2
2
  JavaScript Date builtin module.
3
3
 
4
4
  Usage:
5
- from pulse.js import Date
6
- Date() # -> new Date()
7
- Date.now() # -> Date.now()
8
- Date.parse("2023-01-01") # -> Date.parse("2023-01-01")
9
5
 
10
- # Or import from module directly:
11
- from pulse.js.date import Date
6
+ ```python
7
+ from pulse.js import Date
8
+ Date() # -> new Date()
9
+ Date.now() # -> Date.now()
10
+ Date.parse("2023-01-01") # -> Date.parse("2023-01-01")
11
+
12
+ # Or import from module directly:
13
+ from pulse.js.date import Date
14
+ ```
12
15
  """
13
16
 
14
17
  from typing import Any as _Any
pulse/js/document.py CHANGED
@@ -1,8 +1,11 @@
1
1
  """Browser document global object.
2
2
 
3
3
  Usage:
4
- from pulse.js import document
5
- document.querySelector("#app") # -> document.querySelector("#app")
4
+
5
+ ```python
6
+ from pulse.js import document
7
+ document.querySelector("#app") # -> document.querySelector("#app")
8
+ ```
6
9
  """
7
10
 
8
11
  from collections.abc import Callable as _Callable
pulse/js/error.py CHANGED
@@ -2,11 +2,14 @@
2
2
  JavaScript Error builtin module.
3
3
 
4
4
  Usage:
5
- from pulse.js import Error
6
- Error("message") # -> new Error("message")
7
5
 
8
- from pulse.js.error import TypeError, RangeError, ReferenceError
9
- TypeError("message") # -> new TypeError("message")
6
+ ```python
7
+ from pulse.js import Error
8
+ Error("message") # -> new Error("message")
9
+
10
+ from pulse.js.error import TypeError, RangeError, ReferenceError
11
+ TypeError("message") # -> new TypeError("message")
12
+ ```
10
13
  """
11
14
 
12
15
  from pulse.transpiler.js_module import JsModule
pulse/js/json.py CHANGED
@@ -2,13 +2,16 @@
2
2
  JavaScript JSON builtin module.
3
3
 
4
4
  Usage:
5
- import pulse.js.json as JSON
6
- JSON.stringify({"a": 1}) # -> JSON.stringify({"a": 1})
7
- JSON.parse('{"a": 1}') # -> JSON.parse('{"a": 1}')
8
5
 
9
- from pulse.js.json import stringify, parse
10
- stringify({"a": 1}) # -> JSON.stringify({"a": 1})
11
- parse('{"a": 1}') # -> JSON.parse('{"a": 1}')
6
+ ```python
7
+ import pulse.js.json as JSON
8
+ JSON.stringify({"a": 1}) # -> JSON.stringify({"a": 1})
9
+ JSON.parse('{"a": 1}') # -> JSON.parse('{"a": 1}')
10
+
11
+ from pulse.js.json import stringify, parse
12
+ stringify({"a": 1}) # -> JSON.stringify({"a": 1})
13
+ parse('{"a": 1}') # -> JSON.parse('{"a": 1}')
14
+ ```
12
15
  """
13
16
 
14
17
  from collections.abc import Callable as _Callable
pulse/js/map.py CHANGED
@@ -2,12 +2,15 @@
2
2
  JavaScript Map builtin module.
3
3
 
4
4
  Usage:
5
- from pulse.js import Map
6
- Map() # -> new Map()
7
- Map([["a", 1]]) # -> new Map([["a", 1]])
8
5
 
9
- # Or import from module directly:
10
- from pulse.js.map import Map
6
+ ```python
7
+ from pulse.js import Map
8
+ Map() # -> new Map()
9
+ Map([["a", 1]]) # -> new Map([["a", 1]])
10
+
11
+ # Or import from module directly:
12
+ from pulse.js.map import Map
13
+ ```
11
14
  """
12
15
 
13
16
  from collections.abc import Callable as _Callable
pulse/js/math.py CHANGED
@@ -2,13 +2,16 @@
2
2
  JavaScript Math builtin module.
3
3
 
4
4
  Usage:
5
- import pulse.js.math as Math
6
- Math.PI # -> Math.PI
7
- Math.floor(3.7) # -> Math.floor(3.7)
8
5
 
9
- from pulse.js.math import PI, floor
10
- PI # -> Math.PI
11
- floor(3.7) # -> Math.floor(3.7)
6
+ ```python
7
+ import pulse.js.math as Math
8
+ Math.PI # -> Math.PI
9
+ Math.floor(3.7) # -> Math.floor(3.7)
10
+
11
+ from pulse.js.math import PI, floor
12
+ PI # -> Math.PI
13
+ floor(3.7) # -> Math.floor(3.7)
14
+ ```
12
15
  """
13
16
 
14
17
  from pulse.transpiler.js_module import JsModule
pulse/js/navigator.py CHANGED
@@ -1,8 +1,11 @@
1
1
  """Browser navigator global object.
2
2
 
3
3
  Usage:
4
- from pulse.js import navigator, console
5
- console.log(navigator.userAgent)
4
+
5
+ ```python
6
+ from pulse.js import navigator, console
7
+ console.log(navigator.userAgent)
8
+ ```
6
9
  """
7
10
 
8
11
  from typing import Any as _Any
pulse/js/number.py CHANGED
@@ -2,13 +2,16 @@
2
2
  JavaScript Number builtin module.
3
3
 
4
4
  Usage:
5
- from pulse.js import Number
6
- Number.isFinite(42) # -> Number.isFinite(42)
7
- Number.MAX_SAFE_INTEGER # -> Number.MAX_SAFE_INTEGER
8
- Number(x) # -> new Number(x)
9
5
 
10
- # Or import from module directly:
11
- from pulse.js.number import Number
6
+ ```python
7
+ from pulse.js import Number
8
+ Number.isFinite(42) # -> Number.isFinite(42)
9
+ Number.MAX_SAFE_INTEGER # -> Number.MAX_SAFE_INTEGER
10
+ Number(x) # -> new Number(x)
11
+
12
+ # Or import from module directly:
13
+ from pulse.js.number import Number
14
+ ```
12
15
  """
13
16
 
14
17
  from typing import Any as _Any
pulse/js/obj.py CHANGED
@@ -2,19 +2,22 @@
2
2
  JavaScript object literal creation.
3
3
 
4
4
  Usage:
5
- from pulse.js import obj
6
5
 
7
- # Create plain JS objects (not Maps):
8
- obj(a=1, b=2) # -> { a: 1, b: 2 }
6
+ ```python
7
+ from pulse.js import obj
9
8
 
10
- # With spread syntax:
11
- obj(**base, c=3) # -> { ...base, c: 3 }
12
- obj(a=1, **base) # -> { a: 1, ...base }
9
+ # Create plain JS objects (not Maps):
10
+ obj(a=1, b=2) # -> { a: 1, b: 2 }
13
11
 
14
- # Empty object:
15
- obj() # -> {}
12
+ # With spread syntax:
13
+ obj(**base, c=3) # -> { ...base, c: 3 }
14
+ obj(a=1, **base) # -> { a: 1, ...base }
16
15
 
17
- Unlike dict() which transpiles to new Map(), obj() creates plain JavaScript
16
+ # Empty object:
17
+ obj() # -> {}
18
+ ```
19
+
20
+ Unlike `dict()` which transpiles to `new Map()`, `obj()` creates plain JavaScript
18
21
  object literals. Use this for React props, style objects, and anywhere you
19
22
  need a plain JS object.
20
23
  """
@@ -36,13 +39,13 @@ if TYPE_CHECKING:
36
39
 
37
40
  @dataclass(slots=True)
38
41
  class ObjTransformer(Expr):
39
- """Transformer for obj() with **spread support.
42
+ """Transformer for `obj()` with `**spread` support.
40
43
 
41
- obj(key=value, ...) -> { key: value, ... }
42
- obj(**base, key=value) -> { ...base, key: value }
44
+ - `obj(key=value, ...)` -> `{ key: value, ... }`
45
+ - `obj(**base, key=value)` -> `{ ...base, key: value }`
43
46
 
44
47
  Creates a plain JavaScript object literal.
45
- Use this instead of dict() when you need a plain object (e.g., for React props).
48
+ Use this instead of `dict()` when you need a plain object (e.g., for React props).
46
49
  """
47
50
 
48
51
  @override
pulse/js/object.py CHANGED
@@ -2,13 +2,16 @@
2
2
  JavaScript Object builtin module.
3
3
 
4
4
  Usage:
5
- from pulse.js import Object
6
- Object.keys({"a": 1}) # -> Object.keys({"a": 1})
7
- Object.assign({}, {"a": 1}) # -> Object.assign({}, {"a": 1})
8
- Object.is_(x, y) # -> Object.is(x, y)
9
5
 
10
- # Or import from module directly:
11
- from pulse.js.object import Object
6
+ ```python
7
+ from pulse.js import Object
8
+ Object.keys({"a": 1}) # -> Object.keys({"a": 1})
9
+ Object.assign({}, {"a": 1}) # -> Object.assign({}, {"a": 1})
10
+ Object.is_(x, y) # -> Object.is(x, y)
11
+
12
+ # Or import from module directly:
13
+ from pulse.js.object import Object
14
+ ```
12
15
  """
13
16
 
14
17
  from collections.abc import Iterable as _Iterable
pulse/js/promise.py CHANGED
@@ -2,15 +2,18 @@
2
2
  JavaScript Promise builtin module.
3
3
 
4
4
  Usage:
5
- from pulse.js import Promise
6
- Promise(executor) # -> new Promise(executor)
7
- Promise.resolve(value) # -> Promise.resolve(value)
8
- Promise.reject(reason) # -> Promise.reject(reason)
9
5
 
10
- # Or import from module directly:
11
- from pulse.js.promise import Promise
6
+ ```python
7
+ from pulse.js import Promise
8
+ Promise(executor) # -> new Promise(executor)
9
+ Promise.resolve(value) # -> Promise.resolve(value)
10
+ Promise.reject(reason) # -> Promise.reject(reason)
12
11
 
13
- The Promise class is generic and supports async/await via the Awaitable protocol.
12
+ # Or import from module directly:
13
+ from pulse.js.promise import Promise
14
+ ```
15
+
16
+ The `Promise` class is generic and supports async/await via the Awaitable protocol.
14
17
  """
15
18
 
16
19
  from collections.abc import Callable as _Callable
@@ -36,16 +39,19 @@ PromiseSettledResult = PromiseFulfilledResult[T] | PromiseRejectedResult
36
39
  class Promise(_Generic[T_co]):
37
40
  """JavaScript Promise - a thenable that represents an async operation.
38
41
 
39
- Promise is both generic over its resolved type and implements Awaitable,
42
+ `Promise` is both generic over its resolved type and implements `Awaitable`,
40
43
  allowing it to be used with Python's async/await syntax which transpiles
41
44
  to JavaScript async/await.
42
45
 
43
46
  Example:
44
- @javascript
45
- async def fetch_data() -> str:
46
- response: Promise[Response] = fetch("/api/data")
47
- data = await response # Awaits the promise
48
- return data.text()
47
+
48
+ ```python
49
+ @javascript
50
+ async def fetch_data() -> str:
51
+ response: Promise[Response] = fetch("/api/data")
52
+ data = await response # Awaits the promise
53
+ return data.text()
54
+ ```
49
55
  """
50
56
 
51
57
  def __init__(
pulse/js/pulse.py CHANGED
@@ -2,31 +2,34 @@
2
2
  Pulse UI client bindings for channel communication.
3
3
 
4
4
  Usage:
5
- from pulse.js.pulse import usePulseChannel, ChannelBridge, PulseChannelResetError
6
-
7
- @ps.javascript(jsx=True)
8
- def MyChannelComponent(*, channel_id: str):
9
- bridge = usePulseChannel(channel_id)
10
-
11
- # Subscribe to events
12
- useEffect(
13
- lambda: bridge.on("server:notify", lambda payload: console.log(payload)),
14
- [bridge],
15
- )
16
-
17
- # Emit events to server
18
- def send_ping():
19
- bridge.emit("client:ping", {"message": "hello"})
20
-
21
- # Make requests to server
22
- async def send_request():
23
- response = await bridge.request("client:request", {"data": 123})
24
- console.log(response)
25
-
26
- return ps.div()[
27
- ps.button(onClick=send_ping)["Send Ping"],
28
- ps.button(onClick=send_request)["Send Request"],
29
- ]
5
+
6
+ ```python
7
+ from pulse.js.pulse import usePulseChannel, ChannelBridge, PulseChannelResetError
8
+
9
+ @ps.javascript(jsx=True)
10
+ def MyChannelComponent(*, channel_id: str):
11
+ bridge = usePulseChannel(channel_id)
12
+
13
+ # Subscribe to events
14
+ useEffect(
15
+ lambda: bridge.on("server:notify", lambda payload: console.log(payload)),
16
+ [bridge],
17
+ )
18
+
19
+ # Emit events to server
20
+ def send_ping():
21
+ bridge.emit("client:ping", {"message": "hello"})
22
+
23
+ # Make requests to server
24
+ async def send_request():
25
+ response = await bridge.request("client:request", {"data": 123})
26
+ console.log(response)
27
+
28
+ return ps.div()[
29
+ ps.button(onClick=send_ping)["Send Ping"],
30
+ ps.button(onClick=send_request)["Send Request"],
31
+ ]
32
+ ```
30
33
  """
31
34
 
32
35
  from collections.abc import Awaitable as _Awaitable