Skip to content

Commit 3c5dffd

Browse files
Multi-node client (#52)
* use custom openapi generator template * feat(openapi-template): bon builder derive, generic model and API method * feat: `x-rust-return-type`to override generated API methods' return type fix: missing generic in impl block * feat: bon builder string into conversion * feat: multi-node client * fix: avoid JSON serializing the request body of endpoints that accept plain text (JSONL) * feat: multi search * refactor multi search extension * fix lint * rename folder from `custom-template` to `openapi-generator-template` and remove unused templates * refactor: `to_owned` instead of `to_string` * ci: remove httpmock, ci with real Typesense server * ci: use typesense v30.0.rc10 * ignore rust fmt for `typesense_codegen` * feat: explicit `x-rust-builder: true` to generate builders for open api models * rename `x-rust-operation-generic-parameter` to `x-rust-generic-parameter` * make `perform_union` generic and remove `UnionSearchResultExt` * use String instead of reqwest::Url for node configuration * don't `pub use models::*` at the root * Optimize + fmt * inline * Get next node faster for a single node config * feat: add openapi vendor attributes directly through xtask * Workspace dependencies * run cargo fmt after code-gen task * Refactor execute_wrapper * collection_name ref str * codegen apis ref params * README: add instructions to use the xtask * Readme tweak * README: code gen docker command * remove unused openapi template files * modify the open api template instead of ignoring`apis/mod.rs` and `lib.rs` * remove `openapi-generator-template/request.rs` * expose pub ResponseContent * Avoid apikey clone * Rename generic * Rename: collection() requires trait Document * Node::set_health * Legacy API * Fix test --------- Co-authored-by: RoDmitry <[email protected]>
1 parent 6de9902 commit 3c5dffd

File tree

315 files changed

+23933
-3906
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

315 files changed

+23933
-3906
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
11
name: CI
22

33
on:
4+
workflow_dispatch:
45
push:
56
branches:
67
- main
8+
paths-ignore:
9+
- '**/*.md'
710
pull_request:
811
branches:
912
- main
13+
paths-ignore:
14+
- '**/*.md'
1015

1116
jobs:
1217
tests:
13-
runs-on: "${{ matrix.platform.os }}-latest"
18+
runs-on: '${{ matrix.platform.os }}-latest'
1419
strategy:
1520
matrix:
16-
platform: [
17-
{ os: "ubuntu", target: "x86_64-unknown-linux-gnu" },
18-
{ os: "ubuntu", target: "wasm32-unknown-unknown" },
19-
]
20-
env:
21-
# used to connect to httpmock
22-
URL: "http://localhost:5000"
23-
API_KEY: "VerySecretKey"
21+
platform:
22+
[
23+
{ os: 'ubuntu', target: 'x86_64-unknown-linux-gnu' },
24+
{ os: 'ubuntu', target: 'wasm32-unknown-unknown' },
25+
]
26+
services:
27+
typesense:
28+
image: typesense/typesense:30.0.rc10
29+
ports:
30+
- 8108:8108/tcp
31+
volumes:
32+
- /tmp/typesense-server-data:/data
33+
env:
34+
TYPESENSE_DATA_DIR: '/data'
35+
TYPESENSE_API_KEY: 'xyz'
36+
TYPESENSE_ENABLE_CORS: true
37+
TYPESENSE_URL: 'http://localhost:8108'
2438
steps:
2539
- uses: actions/checkout@v4
2640
- name: Cache .cargo and target
@@ -38,16 +52,9 @@ jobs:
3852
target: ${{ matrix.platform.target }}
3953
profile: minimal
4054
default: true
41-
- name: Install httpmock
42-
uses: actions-rs/cargo@v1
43-
with:
44-
command: install
45-
args: --features standalone -- httpmock
46-
- name: Run httpmock
47-
run: httpmock --expose --mock-files-dir=./mocks &
4855
- name: Install test runner for wasm
4956
if: matrix.platform.target == 'wasm32-unknown-unknown'
50-
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
57+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
5158
- name: Stable Build
5259
uses: actions-rs/cargo@v1
5360
with:

.github/workflows/lint.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
name: Lint checks
22

33
on:
4+
workflow_dispatch:
45
push:
5-
branches: [ main ]
6+
branches:
7+
- main
8+
paths-ignore:
9+
- '**/*.md'
610
pull_request:
7-
branches: [ main ]
11+
branches:
12+
- main
13+
paths-ignore:
14+
- '**/*.md'
815

916
jobs:
1017
lint:
1118
runs-on: ubuntu-latest
1219
env:
13-
TZ: "/usr/share/zoneinfo/your/location"
20+
TZ: '/usr/share/zoneinfo/your/location'
1421
steps:
1522
- uses: actions/checkout@v4
1623
- name: Cache .cargo and target
@@ -28,11 +35,11 @@ jobs:
2835
profile: minimal
2936
default: true
3037
- run: rustup component add rustfmt
31-
- name: Check formt
38+
- name: Check format
3239
uses: actions-rs/cargo@v1
3340
with:
3441
command: fmt
35-
args: --all -- --check
42+
args: -- --check
3643
- run: rustup component add clippy
3744
- name: Run clippy
3845
uses: actions-rs/cargo@v1

Cargo.toml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ repository = "https://github.com/typesense/typesense-rust"
1616
authors = ["Typesense <[email protected]>"]
1717

1818
[workspace.dependencies]
19-
20-
typesense_derive = { path = "./typesense_derive", version = "0.3.0" }
21-
typesense_codegen = { path = "./typesense_codegen", version = "0.25.0" }
19+
typesense_codegen = { path = "./typesense_codegen", version = "0.25" }
20+
typesense_derive = { path = "./typesense_derive", version = "0.3" }
21+
anyhow = "1"
22+
base64 = "0.22"
23+
bon = "3"
24+
clap = { version = "4", features = ["derive"] }
25+
debug_unsafe = "0.1"
26+
hmac = "0.12"
27+
reqwest-retry = "0.7"
28+
serde = { version = "1", features = ["derive"] }
29+
serde_json = "1.0"
30+
serde_repr = "0.1"
31+
serde_yaml = "0.9"
32+
sha2 = "0.10"
33+
thiserror = "2"
34+
url = "2"
35+
web-time = "=1.1.0"

README.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,40 @@
55

66
Community-maintained Rust client library for Typesense | Work In Progress &amp; Help Wanted!
77

8-
OpenAPI codegen folder was generated with:
8+
### Development
9+
10+
When updating or adding new parameters and endpoints, make changes directly in the [Typesense API spec repository](https://github.com/typesense/typesense-api-spec).
11+
12+
Once your changes are merged, you can update this project as follows (you can also run tasks individually):
13+
14+
```bash
15+
cargo xtask fetch code-gen
16+
```
17+
18+
This will:
19+
20+
- Download the latest API spec.
21+
- Write it to our local [`openapi.yml`](./openapi.yml).
22+
- Preprocess it into [`preprocessed_openapi.yml`](./preprocessed_openapi.yml).
23+
- Regenerate the `/typesense_codegen` crate.
24+
25+
The preprocessing step does two things:
26+
27+
- Flatten the URL params defined as objects into individual URL parameters (in [`preprocess_openapi.rs`](xtask/src/preprocess_openapi.rs))
28+
- Inject OpenAPI vendor attributes (e.g., generic parameters, schema builders) into the spec before code generation (in [`add_vendor_attributes.rs`](./xtask/src/add_vendor_attributes.rs))
29+
30+
You can also run `code-gen` directly through Docker:
931

1032
```
1133
docker run --rm \
1234
-v $PWD:/local openapitools/openapi-generator-cli generate \
13-
-i /local/openapi.yml \
35+
-i /local/preprocessed_openapi.yml \
1436
-g rust \
15-
-o /local/typesense_codegen_new
37+
-o /local/typesense_codegen \
38+
-t /local/openapi-generator-template \
39+
--additional-properties library=reqwest \
40+
--additional-properties supportMiddleware=true \
41+
--additional-properties useSingleRequestParameter=true
1642
```
1743

18-
If you'd like to contribute, please join our [Slack Community](https://join.slack.com/t/typesense-community/shared_invite/zt-mx4nbsbn-AuOL89O7iBtvkz136egSJg) and say hello!
44+
If you'd like to contribute, please join our [Slack Community](https://join.slack.com/t/typesense-community/shared_invite/zt-mx4nbsbn-AuOL89O7iBtvkz136egSJg) and say hello!

compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
typesense:
3-
image: typesense/typesense:29.0
3+
image: typesense/typesense:30.0.rc10
44
restart: on-failure
55
ports:
66
- '8108:8108'

mocks/create_collection.yaml

Lines changed: 0 additions & 24 deletions
This file was deleted.

mocks/drop_collection.yaml

Lines changed: 0 additions & 23 deletions
This file was deleted.

mocks/import_documents.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.

mocks/retrieve_all_collections.yaml

Lines changed: 0 additions & 34 deletions
This file was deleted.

mocks/retrieve_collection.yaml

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)