Skip to content

Commit

Permalink
changed rpc.call and rpc.call_async to return bytes instead of python…
Browse files Browse the repository at this point in the history
… objects; reworked docs
  • Loading branch information
westandskif committed Mar 17, 2024
1 parent afba1b6 commit 712c57e
Show file tree
Hide file tree
Showing 32 changed files with 471 additions and 260 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ tags
.s.vim
dist/
node_modules/
tests/int_tst_fastapi/src
tests/int_tst/src
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ test-py%:
test: test-py3.7 test-py3.8 test-py3.9 test-py3.10 test-py3.11 test-py3.12


lock-int-tst-fast-api-py%:
lock-int-tst-py%:
docker run --rm -it \
-v $$PWD:/mnt/${PROJECT} \
-w /mnt/${PROJECT}/tests/int_tst_fastapi \
-w /mnt/${PROJECT}/tests/int_tst \
python:$* bash -c \
"rm -f requirements$*.out && pip install -r requirements$*.in && pip freeze > requirements$*.out"

test/int-tst-fast-api:
cd tests/int_tst_fastapi \
test/int-tst:
cd tests/int_tst \
&& docker compose stop \
&& docker compose build \
&& docker compose up frontend \
Expand Down
1 change: 1 addition & 0 deletions ci-requirements/requirements3.10.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pytest
pytest-cov
pytest-benchmark
pytest-asyncio

pydantic
13 changes: 7 additions & 6 deletions ci-requirements/requirements3.10.out
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
annotated-types==0.6.0
coverage==7.4.1
coverage==7.4.4
exceptiongroup==1.2.0
iniconfig==2.0.0
packaging==23.2
packaging==24.0
pluggy==1.4.0
py-cpuinfo==9.0.0
pydantic==2.6.1
pydantic_core==2.16.2
pytest==8.0.0
pydantic==2.6.4
pydantic_core==2.16.3
pytest==8.1.1
pytest-asyncio==0.23.5.post1
pytest-benchmark==4.0.0
pytest-cov==4.1.0
tomli==2.0.1
typing_extensions==4.9.0
typing_extensions==4.10.0
1 change: 1 addition & 0 deletions ci-requirements/requirements3.11.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pytest
pytest-cov
pytest-benchmark
pytest-asyncio

pydantic
9 changes: 5 additions & 4 deletions ci-requirements/requirements3.11.out
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
annotated-types==0.6.0
coverage==7.4.3
coverage==7.4.4
iniconfig==2.0.0
packaging==23.2
packaging==24.0
pluggy==1.4.0
py-cpuinfo==9.0.0
pydantic==2.6.3
pydantic==2.6.4
pydantic_core==2.16.3
pytest==8.0.2
pytest==8.1.1
pytest-asyncio==0.23.5.post1
pytest-benchmark==4.0.0
pytest-cov==4.1.0
typing_extensions==4.10.0
1 change: 1 addition & 0 deletions ci-requirements/requirements3.12.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pytest
pytest-cov
pytest-benchmark
pytest-asyncio

pydantic
9 changes: 5 additions & 4 deletions ci-requirements/requirements3.12.out
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
annotated-types==0.6.0
coverage==7.4.3
coverage==7.4.4
iniconfig==2.0.0
packaging==23.2
packaging==24.0
pluggy==1.4.0
py-cpuinfo==9.0.0
pydantic==2.6.3
pydantic==2.6.4
pydantic_core==2.16.3
pytest==8.0.2
pytest==8.1.1
pytest-asyncio==0.23.5.post1
pytest-benchmark==4.0.0
pytest-cov==4.1.0
setuptools==69.0.3
Expand Down
1 change: 1 addition & 0 deletions ci-requirements/requirements3.7.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pytest
pytest-cov
pytest-benchmark
pytest-asyncio

pydantic
3 changes: 2 additions & 1 deletion ci-requirements/requirements3.7.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ coverage==7.2.7
exceptiongroup==1.2.0
importlib-metadata==6.7.0
iniconfig==2.0.0
packaging==23.2
packaging==24.0
pluggy==1.2.0
py-cpuinfo==9.0.0
pydantic==2.5.3
pydantic_core==2.14.6
pytest==7.4.4
pytest-asyncio==0.21.1
pytest-benchmark==4.0.0
pytest-cov==4.1.0
tomli==2.0.1
Expand Down
1 change: 1 addition & 0 deletions ci-requirements/requirements3.8.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pytest
pytest-cov
pytest-benchmark
pytest-asyncio

pydantic
9 changes: 5 additions & 4 deletions ci-requirements/requirements3.8.out
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
annotated-types==0.6.0
coverage==7.4.3
coverage==7.4.4
exceptiongroup==1.2.0
iniconfig==2.0.0
packaging==23.2
packaging==24.0
pluggy==1.4.0
py-cpuinfo==9.0.0
pydantic==2.6.3
pydantic==2.6.4
pydantic_core==2.16.3
pytest==8.0.2
pytest==8.1.1
pytest-asyncio==0.23.5.post1
pytest-benchmark==4.0.0
pytest-cov==4.1.0
tomli==2.0.1
Expand Down
8 changes: 8 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.2.0 (2024-03-17)

**Incompatible changes**

- changed `rpc.call` and `rpc.call_async` to return bytes instead of python
dicts/lists


## 0.1.0

Initial version.
46 changes: 39 additions & 7 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ TypeScript client.

## Idea


The below must be enough to define an API:

```python
Expand Down Expand Up @@ -81,8 +82,8 @@ pip install synclane
## Usage

1. define procedures
1. define RPC instance, its error handling method and register procedures
1. dump TypeScript client code
1. define RPC instance, its error handling method, register procedures and dump
TypeScript client code
1. connect RPC to an API
1. on TypeScript side: import `rpcConfig` and initialize:
- `rpcConfig.url`: url where RPC is listening
Expand All @@ -92,18 +93,49 @@ pip install synclane

## Example

/// tab | main.py
#### Step 1: Define procedures

```python
--8<-- "tests/int_tst/main.py:def_procedures"
```

#### Step 2: Define RPC, dump TS

```python
{!../tests/int_tst_fastapi/main.py!}
--8<-- "tests/int_tst/main.py:def_rpc"
```

#### Step 3.a: Connect to Django

/// tab | async rpc
```python
--8<-- "tests/int_tst/main.py:django_async"
```
///

/// tab | sync rpc
```python
--8<-- "tests/int_tst/main.py:django_sync"
```
///

/// tab | client.test.ts
#### Step 3.b: Connect to FastAPI

```typescript
{!../tests/int_tst_fastapi/tests/client.test.ts!}
/// tab | async rpc
```python
--8<-- "tests/int_tst/main.py:fastapi_async"
```
///

/// tab | async rpc
```python
--8<-- "tests/int_tst/main.py:fastapi_sync"
```
///

#### Step 4: Use autogenerated TS client
```typescript
--8<-- "tests/int_tst/tests/client.test.ts:imports"
--8<-- "tests/int_tst/tests/client.test.ts:rpc_config"
--8<-- "tests/int_tst/tests/client.test.ts:get_user"
```
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ markdown_extensions:
use_pygments: true
- pymdownx.inlinehilite:
- pymdownx.superfences:
- pymdownx.snippets:
base_path: .
dedent_subsections: true
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "synclane"
version = "0.1.0"
version = "0.2.0"
description = "framework-agnostic RPC API with a smart auto-generated TypeScript client"
authors = [
{email = "[email protected]", name = "Nikita Almakov"},
Expand Down
Loading

0 comments on commit 712c57e

Please sign in to comment.