typesense 2.1.0.rc2 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +17 -0
- data/Gemfile +1 -0
- data/lib/typesense/api_call.rb +32 -27
- data/lib/typesense/version.rb +1 -1
- data/typesense.gemspec +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 207a723a469821c92408584d89b0d74db1c705e472ab1f7f238cea1640816993
|
4
|
+
data.tar.gz: ce2df2d51c341f60c5f2626810b71d3250e03640ae01cfe5e74cfc0be262ee65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08f5e7ba0388270bb7f510ea9d8150d159673d3cedee6fbaa9e867e5591716add353359af503754aa8da1d75f9732522df106def8a98ce77dae5d1f9ba80b037'
|
7
|
+
data.tar.gz: 58e734bcf1a05efb399e32ceed24827dac1818c9ea669d9b1d99c52707a60854af2305c3275ae863c5cca88fa0142b53f25e53e3c816ed44d4f0c0eb69e1d164
|
data/.github/workflows/tests.yml
CHANGED
@@ -11,8 +11,25 @@ jobs:
|
|
11
11
|
strategy:
|
12
12
|
matrix:
|
13
13
|
ruby-version: ['2.7', '3.0', '3.2']
|
14
|
+
services:
|
15
|
+
typesense:
|
16
|
+
image: typesense/typesense:27.1
|
17
|
+
ports:
|
18
|
+
- 8108:8108
|
19
|
+
volumes:
|
20
|
+
- /tmp/typesense-data:/data
|
21
|
+
- /tmp/typesense-analytics:/analytics
|
22
|
+
env:
|
23
|
+
TYPESENSE_API_KEY: xyz
|
24
|
+
TYPESENSE_DATA_DIR: /data
|
25
|
+
TYPESENSE_ENABLE_CORS: true
|
26
|
+
TYPESENSE_ANALYTICS_DIR: /analytics
|
27
|
+
TYPESENSE_ENABLE_SEARCH_ANALYTICS: true
|
14
28
|
|
15
29
|
steps:
|
30
|
+
- name: Wait for Typesense
|
31
|
+
run: |
|
32
|
+
timeout 20 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8108/health)" != "200" ]]; do sleep 1; done' || false
|
16
33
|
- uses: actions/checkout@v3
|
17
34
|
- uses: ruby/setup-ruby@v1
|
18
35
|
with:
|
data/Gemfile
CHANGED
data/lib/typesense/api_call.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'faraday'
|
4
4
|
require 'oj'
|
5
5
|
|
6
6
|
module Typesense
|
@@ -69,23 +69,25 @@ module Typesense
|
|
69
69
|
@logger.debug "Attempting #{method.to_s.upcase} request Try ##{num_tries} to Node #{node[:index]}"
|
70
70
|
|
71
71
|
begin
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
headers: default_headers.merge(additional_headers)
|
76
|
-
}
|
77
|
-
request_options.merge!(params: query_parameters) unless query_parameters.nil?
|
78
|
-
|
79
|
-
unless body_parameters.nil?
|
80
|
-
body = body_parameters
|
81
|
-
body = Oj.dump(body_parameters, mode: :compat) if request_options[:headers]['Content-Type'] == 'application/json'
|
82
|
-
request_options.merge!(body: body)
|
72
|
+
conn = Faraday.new(uri_for(endpoint, node)) do |f|
|
73
|
+
f.options.timeout = @connection_timeout_seconds
|
74
|
+
f.options.open_timeout = @connection_timeout_seconds
|
83
75
|
end
|
84
76
|
|
85
|
-
|
86
|
-
set_node_healthcheck(node, is_healthy: true) if response.code >= 1 && response.code <= 499
|
77
|
+
headers = default_headers.merge(additional_headers)
|
87
78
|
|
88
|
-
|
79
|
+
response = conn.send(method) do |req|
|
80
|
+
req.headers = headers
|
81
|
+
req.params = query_parameters unless query_parameters.nil?
|
82
|
+
unless body_parameters.nil?
|
83
|
+
body = body_parameters
|
84
|
+
body = Oj.dump(body_parameters, mode: :compat) if headers['Content-Type'] == 'application/json'
|
85
|
+
req.body = body
|
86
|
+
end
|
87
|
+
end
|
88
|
+
set_node_healthcheck(node, is_healthy: true) if response.status >= 1 && response.status <= 499
|
89
|
+
|
90
|
+
@logger.debug "Request #{method}:#{uri_for(endpoint, node)} to Node #{node[:index]} was successfully made (at the network layer). response.status was #{response.status}."
|
89
91
|
|
90
92
|
parsed_response = if response.headers && (response.headers['content-type'] || '').include?('application/json')
|
91
93
|
Oj.load(response.body, mode: :compat)
|
@@ -94,13 +96,15 @@ module Typesense
|
|
94
96
|
end
|
95
97
|
|
96
98
|
# If response is 2xx return the object, else raise the response as an exception
|
97
|
-
return parsed_response if response.
|
99
|
+
return parsed_response if response.status >= 200 && response.status <= 299
|
98
100
|
|
99
101
|
exception_message = (parsed_response && parsed_response['message']) || 'Error'
|
100
102
|
raise custom_exception_klass_for(response), exception_message
|
101
|
-
rescue
|
102
|
-
Errno::
|
103
|
-
|
103
|
+
rescue Faraday::ConnectionFailed, Faraday::TimeoutError,
|
104
|
+
Errno::EINVAL, Errno::ENETDOWN, Errno::ENETUNREACH, Errno::ENETRESET,
|
105
|
+
Errno::ECONNABORTED, Errno::ECONNRESET, Errno::ETIMEDOUT,
|
106
|
+
Errno::ECONNREFUSED, Errno::EHOSTDOWN, Errno::EHOSTUNREACH,
|
107
|
+
Typesense::Error::ServerError, Typesense::Error::HTTPStatus0Error => e
|
104
108
|
# Rescue network layer exceptions and HTTP 5xx errors, so the loop can continue.
|
105
109
|
# Using loops for retries instead of rescue...retry to maintain consistency with client libraries in
|
106
110
|
# other languages that might not support the same construct.
|
@@ -176,23 +180,24 @@ module Typesense
|
|
176
180
|
end
|
177
181
|
|
178
182
|
def custom_exception_klass_for(response)
|
179
|
-
if response.
|
183
|
+
if response.status == 400
|
180
184
|
Typesense::Error::RequestMalformed.new(response: response)
|
181
|
-
elsif response.
|
185
|
+
elsif response.status == 401
|
182
186
|
Typesense::Error::RequestUnauthorized.new(response: response)
|
183
|
-
elsif response.
|
187
|
+
elsif response.status == 404
|
184
188
|
Typesense::Error::ObjectNotFound.new(response: response)
|
185
|
-
elsif response.
|
189
|
+
elsif response.status == 409
|
186
190
|
Typesense::Error::ObjectAlreadyExists.new(response: response)
|
187
|
-
elsif response.
|
191
|
+
elsif response.status == 422
|
188
192
|
Typesense::Error::ObjectUnprocessable.new(response: response)
|
189
|
-
elsif response.
|
193
|
+
elsif response.status >= 500 && response.status <= 599
|
190
194
|
Typesense::Error::ServerError.new(response: response)
|
191
|
-
elsif response.timed_out?
|
195
|
+
elsif response.respond_to?(:timed_out?) && response.timed_out?
|
192
196
|
Typesense::Error::TimeoutError.new(response: response)
|
193
|
-
elsif response.
|
197
|
+
elsif response.status.zero?
|
194
198
|
Typesense::Error::HTTPStatus0Error.new(response: response)
|
195
199
|
else
|
200
|
+
# This will handle both 300-level responses and any other unhandled status codes
|
196
201
|
Typesense::Error::HTTPError.new(response: response)
|
197
202
|
end
|
198
203
|
end
|
data/lib/typesense/version.rb
CHANGED
data/typesense.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ['lib']
|
28
28
|
|
29
|
+
spec.add_dependency 'faraday', '~> 2.8'
|
29
30
|
spec.add_dependency 'oj', '~> 3.16'
|
30
|
-
spec.add_dependency 'typhoeus', '~> 1.4'
|
31
31
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
32
32
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typesense
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Typesense, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.8'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: oj
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.16'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '3.16'
|
41
41
|
description: Typesense is an open source search engine for building a delightful search
|
42
42
|
experience.
|
43
43
|
email:
|