Skip to content

Commit 39e4813

Browse files
committed
Few interface updates.
1 parent 0afb2d5 commit 39e4813

19 files changed

Lines changed: 290 additions & 211 deletions

File tree

python/natsrpy/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from natsrpy._inner import (
22
Nats,
3-
# JetStream,
4-
# Source,
5-
# External,
63
Subscription,
4+
Message,
75
)
86

97
__all__ = [

python/natsrpy/_inner/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from natsrpy._inner.js import JetStream
2+
13
class Message:
24
subject: str
35
reply: str | None
Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
from .kv import KeyValue
2-
3-
class External:
4-
def __init__(
5-
self,
6-
api_prefix: str,
7-
delivery_prefix: str | None = None,
8-
) -> None: ...
9-
10-
class Source:
11-
def __init__(
12-
self,
13-
name: str,
14-
filter_subject: str | None = None,
15-
external: External | None = None,
16-
) -> None: ...
1+
from natsrpy._inner.js.kv import KeyValue, KVConfig
172

183
class JetStream:
194
async def publish(
@@ -25,20 +10,7 @@ class JetStream:
2510
reply: str | None = None,
2611
err_on_disconnect: bool = False,
2712
) -> None: ...
28-
async def create_kv(
29-
self,
30-
bucket: str,
31-
description=None,
32-
max_value_size=None,
33-
history=None,
34-
max_age=None,
35-
max_bytes=None,
36-
storage=None,
37-
num_replicas=None,
38-
republish=None,
39-
mirror: Source | None = None,
40-
mirror_direct=None,
41-
compression=None,
42-
limit_markers=None,
43-
) -> KeyValue: ...
13+
async def create_kv(self, config: KVConfig) -> KeyValue: ...
14+
async def update_kv(self, config: KVConfig) -> KeyValue: ...
4415
async def get_kv(self, bucket: str) -> KeyValue: ...
16+
async def delete_kv(self, bucket: str) -> bool: ...

python/natsrpy/_inner/js/kv.pyi

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,48 @@
1-
2-
class StorageType:
3-
FILE: "StorageType"
4-
MEMORY: "StorageType"
1+
from natsrpy._inner.js.stream import StorageType, Source, Placement, Republish
52

63
class KVConfig:
4+
"""
5+
KV bucket config.
6+
7+
Used for creating or updating KV buckets.
8+
"""
9+
10+
bucket: str
11+
description: str
12+
max_value_size: int | None
13+
history: int | None
14+
max_age: float | None
15+
max_bytes: int | None
16+
storage: StorageType | None
17+
num_replicas: int | None
18+
republish: Republish | None
19+
mirror: Source | None
20+
sources: list[Source] | None
21+
mirror_direct: bool | None
22+
compression: bool | None
23+
placement: Placement | None
24+
limit_markers: float | None
25+
726
def __init__(
827
self,
928
bucket: str,
1029
description: str | None = None,
1130
max_value_size: int | None = None,
12-
history:int|None=None,
13-
max_age:float |None=None,
14-
max_bytes:int |None=None,
15-
storage:StorageType|None=None,
16-
num_replicas: int |None=None,
17-
republish:bool |None=None,
18-
mirror:|None=None,
19-
sources:|None=None,
20-
mirror_direct:|None=None,
21-
compression:|None=None,
22-
placement:|None=None,
23-
limit_markers:|None=None,
31+
history: int | None = None,
32+
max_age: float | None = None,
33+
max_bytes: int | None = None,
34+
storage: StorageType | None = None,
35+
num_replicas: int | None = None,
36+
republish: Republish | None = None,
37+
mirror: Source | None = None,
38+
sources: list[Source] | None = None,
39+
mirror_direct: bool | None = None,
40+
compression: bool | None = None,
41+
placement: Placement | None = None,
42+
limit_markers: float | None = None,
2443
) -> None: ...
2544

2645
class KeyValue:
27-
async def get(self, key: str) -> bytes | None: ...
2846
async def put(self, key: str, value: bytes) -> int: ...
47+
async def get(self, key: str) -> bytes | None: ...
48+
async def delete(self, key: str) -> int: ...

python/natsrpy/_inner/js/stream.pyi

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,44 @@ class StorageType:
22
FILE: "StorageType"
33
MEMORY: "StorageType"
44

5-
class Republish:
5+
class External:
6+
def __init__(
7+
self,
8+
api_prefix: str,
9+
delivery_prefix: str | None = None,
10+
) -> None: ...
11+
12+
class SubjectTransform:
13+
def __init__(
14+
self,
15+
source: str,
16+
destination: str,
17+
) -> None: ...
18+
19+
class Source:
20+
def __init__(
21+
self,
22+
name: str,
23+
filter_subject: str | None = None,
24+
external: External | None = None,
25+
start_sequence: int | None = None,
26+
start_time: int | None = None,
27+
domain: str | None = None,
28+
subject_transforms: SubjectTransform | None = None,
29+
) -> None: ...
630

31+
class Placement:
32+
def __init__(
33+
self,
34+
cluster: str | None = None,
35+
tags: list[str] | None = None,
36+
) -> None: ...
37+
38+
class Republish:
39+
pass
40+
def __init__(
41+
self,
42+
source: str | None = None,
43+
destination: str | None = None,
44+
headers_only: str | None = None,
45+
) -> None: ...

python/natsrpy/_inner/message.pyi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import Any
2+
3+
class Message:
4+
subject: str
5+
reply: str | None
6+
payload: bytes
7+
headers: dict[str, Any]
8+
status: int | None
9+
description: str | None
10+
length: int

python/natsrpy/js/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from natsrpy._inner import jetstream
1+
from natsrpy._inner.js import JetStream
22

3-
from natsrpy._inner.js import External, Source, JetStream
4-
5-
6-
__all__ = ["External", "Source", "JetStream"]
3+
__all__ = ["JetStream"]

python/natsrpy/js/kv.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from natsrpy._inner.js.kv import (
2+
KVConfig,
3+
KeyValue,
4+
)
5+
6+
__all__ = [
7+
"KVConfig",
8+
"KeyValue",
9+
]

python/natsrpy/js/stream.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from natsrpy._inner.js.stream import (
2+
External,
3+
Republish,
4+
Source,
5+
StorageType,
6+
SubjectTransform,
7+
Placement,
8+
)
9+
10+
__all__ = [
11+
"External",
12+
"Republish",
13+
"Source",
14+
"StorageType",
15+
"SubjectTransform",
16+
"Placement",
17+
]

src/exceptions/rust_err.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pub enum NatsrpyError {
4646
KVPutError(#[from] async_nats::jetstream::kv::PutError),
4747
#[error(transparent)]
4848
KVUpdateError(#[from] async_nats::jetstream::context::UpdateKeyValueError),
49+
#[error(transparent)]
50+
DeleteError(#[from] async_nats::jetstream::kv::DeleteError),
4951
}
5052

5153
impl From<NatsrpyError> for pyo3::PyErr {

0 commit comments

Comments
 (0)