Skip to content

Commit

Permalink
open api generator (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeyson authored Jan 20, 2025
1 parent bd42b70 commit fac17da
Show file tree
Hide file tree
Showing 51 changed files with 8,737 additions and 3,349 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text=auto

*.ex diff=elixir
*.exs diff=elixir

69 changes: 50 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,39 @@ jobs:
test:
runs-on: ubuntu-latest

env:
MIX_ENV: test
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LATEST_TYPESENSE: '27.1'

strategy:
matrix:
include:
- typesense: '0.25.2'
- typesense: '26.0'
otp: '25'
elixir: '1.14'
- typesense: '26.0'
lint: false
- typesense: '27.0'
otp: '25'
elixir: '1.14'
lint: false
- typesense: '27.1'
otp: '25'
elixir: '1.14'
- typesense: '0.25.2'
otp: '27'
elixir: '1.17'
lint: false
- typesense: '26.0'
otp: '27'
elixir: '1.17'
elixir: '1.18'
lint: false
- typesense: '27.0'
otp: '27'
elixir: '1.18'
lint: false
- typesense: '27.1'
otp: '27'
elixir: '1.17'
elixir: '1.18'
lint: true

env:
MIX_ENV: test
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

services:
typesense:
image: typesense/typesense:${{ matrix.typesense }}
Expand All @@ -56,19 +62,43 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v4

- name: Check for misspellings
uses: codespell-project/actions-codespell@v2

- name: Start Typesense
run: |
docker run -d \
docker run -id \
-p 8108:8108 \
--name typesense \
-v /tmp/typesense-data:/data \
-v /tmp/typesense-analytics-data:/analytics-data \
typesense/typesense:${{ matrix.typesense}} \
--api-key=xyz \
--data-dir /data \
--data-dir=/data \
--enable-search-analytics=true \
--analytics-dir=/analytics-data \
--analytics-flush-interval=60 \
--analytics-minute-rate-limit=100 \
--enable-cors
- name: Curl Typesense
run: sleep 1 && curl http://localhost:8108/health
- name: Wait for Typesense to be healthy
shell: bash
run: |
start_time=$(date +%s)
timeout=30
counter=0
until curl -s http://localhost:8108/health | grep -q '"ok":true'; do
if [ $counter -eq $timeout ]; then
echo "Timed out waiting for Typesense to be healthy"
exit 1
fi
echo "Waiting for Typesense to be healthy..."
sleep 1
counter=$((counter + 1))
done
end_time=$(date +%s)
elapsed=$((end_time - start_time))
echo "Typesense healthcheck elapsed: ${elapsed}s"
- name: Setup Elixir/OTP
uses: erlef/setup-beam@v1
Expand All @@ -82,9 +112,9 @@ jobs:
path: |
deps
_build
key: ${{ runner.os }}-mix-typesense-${{ matrix.typesense}}-${{ matrix.otp}}-${{ matrix.elixir}}-${{ hashFiles('**/mix.lock') }}
key: ${{ runner.os }}-typesense-${{ matrix.typesense}}-${{ matrix.otp}}-${{ matrix.elixir}}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-typesense-${{ matrix.typesense}}
${{ runner.os }}-typesense-${{ matrix.typesense}}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-
- name: Install Dependencies
run: |
Expand Down Expand Up @@ -116,7 +146,8 @@ jobs:
if: ${{ matrix.lint }}

- name: Run tests
run: mix test
run: mix test --only ${{ matrix.typesense }}:true --trace

- name: Post test coverage to Coveralls
run: mix coveralls.github
run: mix coveralls.github --only ${{ matrix.typesense }}:true --trace
if: ${{ matrix.lint }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ex_typesense-*.tar

# Typesense local dev data folder.
/typesense-data
/typesense-analytics-data

# Misc.
.elixir_ls
Expand Down
51 changes: 42 additions & 9 deletions .iex.exs
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
defmodule ExTypesense.TestSchema.Catalog do
use Ecto.Schema
@behaviour ExTypesense

@moduledoc false

defimpl Jason.Encoder, for: __MODULE__ do
def encode(value, opts) do
value
|> Map.take([:catalogs_id, :name, :description])
|> Enum.map(fn {key, val} ->
if key === :catalogs_id, do: {key, Map.get(value, :id)}, else: {key, val}
end)
|> Enum.into(%{})
|> Jason.Encode.map(opts)
end
end

schema "catalogs" do
field(:name, :string)
field(:description, :string)
field(:catalogs_id, :integer, virtual: true)
end

@impl ExTypesense
def get_field_types do
name = __MODULE__.__schema__(:source)
primary_field = name <> "_id"

%{
name: name,
default_sorting_field: primary_field,
fields: [
%{name: primary_field, type: "int32"},
%{name: "name", type: "string"},
%{name: "description", type: "string"}
]
}
end
end

import Ecto.Query, warn: false
alias ExTypesense.Cluster
alias ExTypesense.Collection
alias ExTypesense.Connection
alias ExTypesense.Document
alias ExTypesense.HttpClient
alias ExTypesense.Search

alias ExTypesense.TestSchema.Catalog
alias ExTypesense.TestSchema.MultiSearch
alias ExTypesense.TestSchema.Person
alias ExTypesense.TestSchema.Product
32 changes: 28 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,45 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

## 1.0.0 (2025.01.19)

### Added

* External docs link for example of using another HTTP client.
* More test coverage

### Changed

* Backwards-incompatible changes, in favor of using [`OpenApiTypesense`](https://github.com/jaeyson/open_api_typesense).
* Bump dependencies
* CI to support Typesense versions v26.0, v27.0, v27.1

### Removed

* Dropped support for Typesense version v0.25.2
* `ExTypesense.ResultParser` module (moved to `ExTypesense.Search`)

### Deprecated

* Dropped support for Typesense v0.25.2

## 0.7.3 (2024.11.11)

### Added

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

## 0.7.2 (2024.11.07)

### Changed

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

## 0.7.1 (2024.09.10)

### Removed

- `:castore` dependency not passing on CI test
* `:castore` dependency not passing on CI test

## 0.7.0 (2024.09.10)

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

### Added

* `options` in config `config/configx.exs`.
* `options` in config `config/config.exs`.
* `get_options/0` function in `HttpClient` to fetch the `options` configuration.
* tests for `get_options/0` in `ExTypesense.HttpClientTest`.

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

### Changed

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

### Added

* Added cheatsheet section on docs.

## 0.2.2 (2023.01.26)
Expand Down
59 changes: 59 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Contributor Covenant Code of Conduct

## Our Pledge

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.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or advances of
any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address,
without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Maintainers have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all this project, and also applies when
an individual is officially representing the community in public spaces.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by opening an issue or contacting one or more of the project maintainers.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.1, available at
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].

[homepage]: https://www.contributor-covenant.org
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Contributing

## Pull Request

1. Fork repo (https://github.com/jaeyson/ex_typesense/fork)
2. Clone to your local machine, `git clone [email protected]:your_username/ex_typesense.git && cd ex_typesense`
3. Create branch, _e.g._ `git checkout -b manage-backups-and-restores`
4. Commit changes, _e.g._ `git commit -am 'manage backups and restores (snapshots)'`
5. Push the new branch, _e.g._ `git push -u origin manage-backups-and-restores`
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)

## Local development

Please refer: https://hexdocs.pm/ex_typesense/running_local_typesense.html
Loading

0 comments on commit fac17da

Please sign in to comment.