typesense 2.1.0 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 821dcb542970fb0e93bfeceed5e47b714ecfb9c0ff8920382b4959b6ddfc8c22
4
- data.tar.gz: e17c06e9cfc5bba67a5cfe92d9a1fb35bd53b4957e9f523f5ca3ee0e819dc518
3
+ metadata.gz: 207a723a469821c92408584d89b0d74db1c705e472ab1f7f238cea1640816993
4
+ data.tar.gz: ce2df2d51c341f60c5f2626810b71d3250e03640ae01cfe5e74cfc0be262ee65
5
5
  SHA512:
6
- metadata.gz: 794ef47d87171bc57c2d51e34883414224f1bb21c46e87a5257b2cb9744ed410da1e776737461d6001b8bf0b0d89b652f92b7d138edc1099789e71f2f7441ef1
7
- data.tar.gz: 894cce3929f9f443d4c8f885717e3b087dc4d122d5943324a9244927eabc90b068d4c39db892aa0c893dfa2eea7b44d0361f826f0448356c13bc2eacfe485bea
6
+ metadata.gz: '08f5e7ba0388270bb7f510ea9d8150d159673d3cedee6fbaa9e867e5591716add353359af503754aa8da1d75f9732522df106def8a98ce77dae5d1f9ba80b037'
7
+ data.tar.gz: 58e734bcf1a05efb399e32ceed24827dac1818c9ea669d9b1d99c52707a60854af2305c3275ae863c5cca88fa0142b53f25e53e3c816ed44d4f0c0eb69e1d164
@@ -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
@@ -8,6 +8,7 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
8
8
  gem 'awesome_print', '~> 1.8'
9
9
  gem 'bundler', '~> 2.0'
10
10
  gem 'codecov', '~> 0.1'
11
+ gem 'erb'
11
12
  gem 'guard', '~> 2.16'
12
13
  gem 'guard-rubocop', '~> 1.3'
13
14
  gem 'rake', '~> 13.0'
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'typhoeus'
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
- request_options = {
73
- method: method,
74
- timeout: @connection_timeout_seconds,
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
- response = Typhoeus::Request.new(uri_for(endpoint, node), request_options).run
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
- @logger.debug "Request #{method}:#{uri_for(endpoint, node)} to Node #{node[:index]} was successfully made (at the network layer). Response Code was #{response.code}."
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.code >= 200 && response.code <= 299
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 Errno::EINVAL, Errno::ENETDOWN, Errno::ENETUNREACH, Errno::ENETRESET, Errno::ECONNABORTED, Errno::ECONNRESET,
102
- Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTDOWN, Errno::EHOSTUNREACH,
103
- Typesense::Error::TimeoutError, Typesense::Error::ServerError, Typesense::Error::HTTPStatus0Error => e
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.code == 400
183
+ if response.status == 400
180
184
  Typesense::Error::RequestMalformed.new(response: response)
181
- elsif response.code == 401
185
+ elsif response.status == 401
182
186
  Typesense::Error::RequestUnauthorized.new(response: response)
183
- elsif response.code == 404
187
+ elsif response.status == 404
184
188
  Typesense::Error::ObjectNotFound.new(response: response)
185
- elsif response.code == 409
189
+ elsif response.status == 409
186
190
  Typesense::Error::ObjectAlreadyExists.new(response: response)
187
- elsif response.code == 422
191
+ elsif response.status == 422
188
192
  Typesense::Error::ObjectUnprocessable.new(response: response)
189
- elsif response.code >= 500 && response.code <= 599
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.code.zero?
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Typesense
4
- VERSION = '2.1.0'
4
+ VERSION = '3.0.0.rc1'
5
5
  end
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: 2.1.0
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-05 00:00:00.000000000 Z
11
+ date: 2024-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: oj
14
+ name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.16'
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: '3.16'
26
+ version: '2.8'
27
27
  - !ruby/object:Gem::Dependency
28
- name: typhoeus
28
+ name: oj
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.4'
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: '1.4'
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:
@@ -111,9 +111,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
111
  version: '2.7'
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - ">="
114
+ - - ">"
115
115
  - !ruby/object:Gem::Version
116
- version: '0'
116
+ version: 1.3.1
117
117
  requirements: []
118
118
  rubygems_version: 3.4.10
119
119
  signing_key: