Skip to content

Commit fac17da

Browse files
authored
open api generator (#47)
1 parent bd42b70 commit fac17da

Some content is hidden

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

51 files changed

+8737
-3349
lines changed

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* text=auto
2+
3+
*.ex diff=elixir
4+
*.exs diff=elixir
5+

.github/workflows/ci.yml

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,39 @@ jobs:
2121
test:
2222
runs-on: ubuntu-latest
2323

24+
env:
25+
MIX_ENV: test
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
LATEST_TYPESENSE: '27.1'
28+
2429
strategy:
2530
matrix:
2631
include:
27-
- typesense: '0.25.2'
32+
- typesense: '26.0'
2833
otp: '25'
2934
elixir: '1.14'
30-
- typesense: '26.0'
35+
lint: false
36+
- typesense: '27.0'
3137
otp: '25'
3238
elixir: '1.14'
39+
lint: false
3340
- typesense: '27.1'
3441
otp: '25'
3542
elixir: '1.14'
36-
- typesense: '0.25.2'
37-
otp: '27'
38-
elixir: '1.17'
43+
lint: false
3944
- typesense: '26.0'
4045
otp: '27'
41-
elixir: '1.17'
46+
elixir: '1.18'
47+
lint: false
48+
- typesense: '27.0'
49+
otp: '27'
50+
elixir: '1.18'
51+
lint: false
4252
- typesense: '27.1'
4353
otp: '27'
44-
elixir: '1.17'
54+
elixir: '1.18'
4555
lint: true
4656

47-
env:
48-
MIX_ENV: test
49-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50-
5157
services:
5258
typesense:
5359
image: typesense/typesense:${{ matrix.typesense }}
@@ -56,19 +62,43 @@ jobs:
5662
- name: Checkout repo
5763
uses: actions/checkout@v4
5864

65+
- name: Check for misspellings
66+
uses: codespell-project/actions-codespell@v2
67+
5968
- name: Start Typesense
6069
run: |
61-
docker run -d \
70+
docker run -id \
6271
-p 8108:8108 \
6372
--name typesense \
6473
-v /tmp/typesense-data:/data \
74+
-v /tmp/typesense-analytics-data:/analytics-data \
6575
typesense/typesense:${{ matrix.typesense}} \
6676
--api-key=xyz \
67-
--data-dir /data \
77+
--data-dir=/data \
78+
--enable-search-analytics=true \
79+
--analytics-dir=/analytics-data \
80+
--analytics-flush-interval=60 \
81+
--analytics-minute-rate-limit=100 \
6882
--enable-cors
6983
70-
- name: Curl Typesense
71-
run: sleep 1 && curl http://localhost:8108/health
84+
- name: Wait for Typesense to be healthy
85+
shell: bash
86+
run: |
87+
start_time=$(date +%s)
88+
timeout=30
89+
counter=0
90+
until curl -s http://localhost:8108/health | grep -q '"ok":true'; do
91+
if [ $counter -eq $timeout ]; then
92+
echo "Timed out waiting for Typesense to be healthy"
93+
exit 1
94+
fi
95+
echo "Waiting for Typesense to be healthy..."
96+
sleep 1
97+
counter=$((counter + 1))
98+
done
99+
end_time=$(date +%s)
100+
elapsed=$((end_time - start_time))
101+
echo "Typesense healthcheck elapsed: ${elapsed}s"
72102
73103
- name: Setup Elixir/OTP
74104
uses: erlef/setup-beam@v1
@@ -82,9 +112,9 @@ jobs:
82112
path: |
83113
deps
84114
_build
85-
key: ${{ runner.os }}-mix-typesense-${{ matrix.typesense}}-${{ matrix.otp}}-${{ matrix.elixir}}-${{ hashFiles('**/mix.lock') }}
115+
key: ${{ runner.os }}-typesense-${{ matrix.typesense}}-${{ matrix.otp}}-${{ matrix.elixir}}-mix-${{ hashFiles('**/mix.lock') }}
86116
restore-keys: |
87-
${{ runner.os }}-mix-typesense-${{ matrix.typesense}}
117+
${{ runner.os }}-typesense-${{ matrix.typesense}}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-
88118
89119
- name: Install Dependencies
90120
run: |
@@ -116,7 +146,8 @@ jobs:
116146
if: ${{ matrix.lint }}
117147

118148
- name: Run tests
119-
run: mix test
149+
run: mix test --only ${{ matrix.typesense }}:true --trace
120150

121151
- name: Post test coverage to Coveralls
122-
run: mix coveralls.github
152+
run: mix coveralls.github --only ${{ matrix.typesense }}:true --trace
153+
if: ${{ matrix.lint }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ ex_typesense-*.tar
3030

3131
# Typesense local dev data folder.
3232
/typesense-data
33+
/typesense-analytics-data
3334

3435
# Misc.
3536
.elixir_ls

.iex.exs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
1+
defmodule ExTypesense.TestSchema.Catalog do
2+
use Ecto.Schema
3+
@behaviour ExTypesense
4+
5+
@moduledoc false
6+
7+
defimpl Jason.Encoder, for: __MODULE__ do
8+
def encode(value, opts) do
9+
value
10+
|> Map.take([:catalogs_id, :name, :description])
11+
|> Enum.map(fn {key, val} ->
12+
if key === :catalogs_id, do: {key, Map.get(value, :id)}, else: {key, val}
13+
end)
14+
|> Enum.into(%{})
15+
|> Jason.Encode.map(opts)
16+
end
17+
end
18+
19+
schema "catalogs" do
20+
field(:name, :string)
21+
field(:description, :string)
22+
field(:catalogs_id, :integer, virtual: true)
23+
end
24+
25+
@impl ExTypesense
26+
def get_field_types do
27+
name = __MODULE__.__schema__(:source)
28+
primary_field = name <> "_id"
29+
30+
%{
31+
name: name,
32+
default_sorting_field: primary_field,
33+
fields: [
34+
%{name: primary_field, type: "int32"},
35+
%{name: "name", type: "string"},
36+
%{name: "description", type: "string"}
37+
]
38+
}
39+
end
40+
end
41+
142
import Ecto.Query, warn: false
2-
alias ExTypesense.Cluster
3-
alias ExTypesense.Collection
4-
alias ExTypesense.Connection
5-
alias ExTypesense.Document
6-
alias ExTypesense.HttpClient
7-
alias ExTypesense.Search
43+
844
alias ExTypesense.TestSchema.Catalog
9-
alias ExTypesense.TestSchema.MultiSearch
10-
alias ExTypesense.TestSchema.Person
11-
alias ExTypesense.TestSchema.Product

CHANGELOG.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,45 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## major.minor.patch (yyyy.mm.dd)
99

10+
## 1.0.0 (2025.01.19)
11+
12+
### Added
13+
14+
* External docs link for example of using another HTTP client.
15+
* More test coverage
16+
17+
### Changed
18+
19+
* Backwards-incompatible changes, in favor of using [`OpenApiTypesense`](https://github.com/jaeyson/open_api_typesense).
20+
* Bump dependencies
21+
* CI to support Typesense versions v26.0, v27.0, v27.1
22+
23+
### Removed
24+
25+
* Dropped support for Typesense version v0.25.2
26+
* `ExTypesense.ResultParser` module (moved to `ExTypesense.Search`)
27+
28+
### Deprecated
29+
30+
* Dropped support for Typesense v0.25.2
31+
1032
## 0.7.3 (2024.11.11)
1133

1234
### Added
1335

14-
- `{:error, String.t()}` type for `Search.search/3`
36+
* `{:error, String.t()}` type for `Search.search/3`
1537

1638
## 0.7.2 (2024.11.07)
1739

1840
### Changed
1941

20-
- Use `v27.1` of [Typesense](https://typesense.org/docs/27.1/api) in CI and local development.
42+
* Use `v27.1` of [Typesense](https://typesense.org/docs/27.1/api) in CI and local development.
2143

2244
## 0.7.1 (2024.09.10)
2345

2446
### Removed
2547

26-
- `:castore` dependency not passing on CI test
48+
* `:castore` dependency not passing on CI test
2749

2850
## 0.7.0 (2024.09.10)
2951

@@ -34,7 +56,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3456

3557
### Added
3658

37-
* `options` in config `config/configx.exs`.
59+
* `options` in config `config/config.exs`.
3860
* `get_options/0` function in `HttpClient` to fetch the `options` configuration.
3961
* tests for `get_options/0` in `ExTypesense.HttpClientTest`.
4062

@@ -143,11 +165,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
143165
* Fixed url request path for aliases.
144166

145167
### Changed
168+
146169
* Refactor functions inside collection and document.
147170
* Changed return values from `{:ok, t()}` to `t()` only.
148171
* Parse schema field types for `float`, `boolean`, `string`, `integer` and a list with these corresponding types.
149172

150173
### Added
174+
151175
* Added cheatsheet section on docs.
152176

153177
## 0.2.2 (2023.01.26)

CODE_OF_CONDUCT.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as the maintainers of this project, respects all people who contributes via raising issues, submission of requests, enhancement of documentation, patches and rest of activities regardless of the level of experience. We aim an inclusive, diverse, welcoming, open, and healthy interaction towards the community.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to a positive environment for our
10+
community include:
11+
12+
* Demonstrating empathy and kindness toward other people
13+
* Being respectful of differing opinions, viewpoints, and experiences
14+
* Giving and gracefully accepting constructive feedback
15+
* Accepting responsibility and apologizing to those affected by our mistakes,
16+
and learning from the experience
17+
* Focusing on what is best not just for us as individuals, but for the overall
18+
community
19+
20+
Examples of unacceptable behavior include:
21+
22+
* The use of sexualized language or imagery, and sexual attention or advances of
23+
any kind
24+
* Trolling, insulting or derogatory comments, and personal or political attacks
25+
* Public or private harassment
26+
* Publishing others' private information, such as a physical or email address,
27+
without their explicit permission
28+
* Other conduct which could reasonably be considered inappropriate in a
29+
professional setting
30+
31+
## Enforcement Responsibilities
32+
33+
Maintainers have the right and responsibility to remove, edit, or reject
34+
comments, commits, code, wiki edits, issues, and other contributions that are
35+
not aligned to this Code of Conduct, and will communicate reasons for moderation
36+
decisions when appropriate.
37+
38+
## Scope
39+
40+
This Code of Conduct applies within all this project, and also applies when
41+
an individual is officially representing the community in public spaces.
42+
43+
## Enforcement
44+
45+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
46+
reported by opening an issue or contacting one or more of the project maintainers.
47+
All complaints will be reviewed and investigated promptly and fairly.
48+
49+
All community leaders are obligated to respect the privacy and security of the
50+
reporter of any incident.
51+
52+
## Attribution
53+
54+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
55+
version 2.1, available at
56+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
57+
58+
[homepage]: https://www.contributor-covenant.org
59+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Contributing
2+
3+
## Pull Request
4+
5+
1. Fork repo (https://github.com/jaeyson/ex_typesense/fork)
6+
2. Clone to your local machine, `git clone [email protected]:your_username/ex_typesense.git && cd ex_typesense`
7+
3. Create branch, _e.g._ `git checkout -b manage-backups-and-restores`
8+
4. Commit changes, _e.g._ `git commit -am 'manage backups and restores (snapshots)'`
9+
5. Push the new branch, _e.g._ `git push -u origin manage-backups-and-restores`
10+
6. [Create new Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)
11+
12+
## Local development
13+
14+
Please refer: https://hexdocs.pm/ex_typesense/running_local_typesense.html

0 commit comments

Comments
 (0)