statepatch 0.2.2__py3-none-any.whl → 0.3.0__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.
statepatch/__init__.py CHANGED
@@ -7,7 +7,7 @@ stream at that path; removing it detaches it, live and reusable.
7
7
  """
8
8
 
9
9
  from ._core import Observable, Proxy, append, observable
10
- from ._wire import Listener, Op, Path, Segment, plain, snapshot
10
+ from ._wire import Listener, Op, Path, Segment, WireEncodingError, plain, snapshot
11
11
 
12
12
  __all__ = [
13
13
  "observable",
@@ -20,4 +20,5 @@ __all__ = [
20
20
  "Path",
21
21
  "Segment",
22
22
  "Listener",
23
+ "WireEncodingError",
23
24
  ]
statepatch/_wire.py CHANGED
@@ -21,6 +21,10 @@ _MAX_SAFE_INT = 2**53 - 1
21
21
  _MISSING: Any = object()
22
22
 
23
23
 
24
+ class WireEncodingError(ValueError):
25
+ """A value failed Statepatch's wire validation."""
26
+
27
+
24
28
  def _snapshot(node: Any) -> Any:
25
29
  from ._core import Observable, Proxy
26
30
 
@@ -70,17 +74,17 @@ def _adopt(value: Any, base: Path) -> tuple[Any, list[tuple[Path, "Observable"]]
70
74
  return value
71
75
  if isinstance(value, float):
72
76
  if math.isnan(value) or math.isinf(value):
73
- raise ValueError(f"{value!r} is not wire-encodable; floats must be finite")
77
+ raise WireEncodingError(f"{value!r} is not wire-encodable; floats must be finite")
74
78
  return value
75
79
  if isinstance(value, int):
76
80
  if abs(value) > _MAX_SAFE_INT:
77
- raise ValueError(
81
+ raise WireEncodingError(
78
82
  f"integer {value} exceeds the JS safe range (|n| <= 2**53-1); send it as a string"
79
83
  )
80
84
  return value
81
85
  if isinstance(value, datetime):
82
86
  if value.tzinfo is None or value.tzinfo.utcoffset(value) is None:
83
- raise ValueError("naive datetime is not wire-encodable; attach a timezone")
87
+ raise WireEncodingError("naive datetime is not wire-encodable; attach a timezone")
84
88
  return value
85
89
  if isinstance(value, (list, tuple)):
86
90
  return [walk(item, path + (i,)) for i, item in enumerate(value)]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: statepatch
3
- Version: 0.2.2
3
+ Version: 0.3.0
4
4
  Summary: Immer-style ops over a plain JSON tree: observables that emit every mutation as an op
5
5
  Project-URL: Repository, https://github.com/assistant-ui/harness-sdk
6
6
  License-Expression: MIT
@@ -31,6 +31,10 @@ run["queue"].append({"id": "q1"}) # forwarded as add at ["runs", 0, "queue", 0]
31
31
  state["runs"].pop(0) # remove op; run is detached and reusable
32
32
  ```
33
33
 
34
+ ## Validation
35
+
36
+ `from statepatch import WireEncodingError` exposes the `ValueError` subclass for invalid wire values.
37
+
34
38
  ## Docs
35
39
 
36
40
  - Reference: https://github.com/assistant-ui/harness-sdk/blob/main/apps/docs/app/docs/reference/packages/page.mdx
@@ -0,0 +1,6 @@
1
+ statepatch/__init__.py,sha256=XoHpDb8Kj8pq2ThmMTdfOHO31ughbii-pdW-LXx5R4I,661
2
+ statepatch/_core.py,sha256=lP_EJmpxp0oYkBIA43MsmVsevDScpxleatkiIQC-RWE,16563
3
+ statepatch/_wire.py,sha256=zs7wNJXK2J_xhMR6GEeBN1yfmMiEG9pfv5BK5VONYF4,3679
4
+ statepatch-0.3.0.dist-info/METADATA,sha256=p7Pxe3mA9V9C-7Rx-8kzm1b_1OARIp9Ab4MKdSnbmC4,1587
5
+ statepatch-0.3.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
6
+ statepatch-0.3.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.32.0
2
+ Generator: hatchling 1.32.4
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,6 +0,0 @@
1
- statepatch/__init__.py,sha256=feJjPX5yyOk0xCHx0mvXK1goVjzHgyM4yNax0RVzIOA,617
2
- statepatch/_core.py,sha256=lP_EJmpxp0oYkBIA43MsmVsevDScpxleatkiIQC-RWE,16563
3
- statepatch/_wire.py,sha256=tWYFXl5J6EiE5VHMUV5W1mrVABXBY-offNigZhbGZ70,3564
4
- statepatch-0.2.2.dist-info/METADATA,sha256=AWtW9dl8Q7-1Q0vDKtS34Tz1ftq3vFbs-3dkoGmDv9g,1469
5
- statepatch-0.2.2.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
6
- statepatch-0.2.2.dist-info/RECORD,,