statepatch 0.2.2__tar.gz → 0.3.0__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.
@@ -28,3 +28,10 @@ apps/docs/.docs
28
28
 
29
29
  MAINTAIN_EPOCH.md
30
30
  DOCS_EPOCH.md
31
+
32
+ # terraform
33
+ .terraform/
34
+ *.tfstate
35
+ *.tfstate.*
36
+ *.tfvars
37
+ !*.tfvars.example
@@ -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
@@ -22,6 +22,10 @@ run["queue"].append({"id": "q1"}) # forwarded as add at ["runs", 0, "queue", 0]
22
22
  state["runs"].pop(0) # remove op; run is detached and reusable
23
23
  ```
24
24
 
25
+ ## Validation
26
+
27
+ `from statepatch import WireEncodingError` exposes the `ValueError` subclass for invalid wire values.
28
+
25
29
  ## Docs
26
30
 
27
31
  - Reference: https://github.com/assistant-ui/harness-sdk/blob/main/apps/docs/app/docs/reference/packages/page.mdx
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "statepatch"
3
- version = "0.2.2"
3
+ version = "0.3.0"
4
4
  description = "Immer-style ops over a plain JSON tree: observables that emit every mutation as an op"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -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
  ]
@@ -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)]