elasticgraph-support 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4385b468e82bf7dbfc35f5ea06cb1a3e7249f3db6a45f3eec13e181304c21eae
4
- data.tar.gz: c949877479f1f6370a2cdccd9602d20fe1bacf6e6c28795a175287c0314bdab8
3
+ metadata.gz: fdd7d18e2d13299ff5246ab37ea242654bb8be5eded1f13ea0f9732f1df3f4a7
4
+ data.tar.gz: d2166983bf06daa7b8e060ec4c943dd5a51b7de987c2c8790ae39612f2aeff1a
5
5
  SHA512:
6
- metadata.gz: 0cc21f5f3b52d1d74f0f25f67147ed79de1b8c6ec4f5a9d59365b6a52e63b03bd8ac236a7247e7e2dcbe35225aa34842398ff6d41251e0831c48f9e0a8034038
7
- data.tar.gz: f5318376302d6dab15ca81942f5716dfd2a9983469bfe863ea40d2517baaff1a0425c1c54457be313b3e1050a67164e1c03afac2ef93b6907f9632de58671b29
6
+ metadata.gz: 6c77c47ce1914a3828ef6ee3041d51ddc54450d3c210cdbd8a2a2493c64c0ea05d926d7f6096e8bbad142b479bdad7923f2b16bef6ae03b3fedd04cbf3ac2264
7
+ data.tar.gz: '097f7b5a51df6761ec612f10f4502c994e6a48c0f9014f49c3ed23a08c5ec6a08ea1fd457cc291553519d9c57ee8c43c730c53bb55a9df6f356593b9d286bc83'
@@ -36,6 +36,10 @@ module ElasticGraph
36
36
  # @private
37
37
  TIMEOUT_MS_HEADER = "ElasticGraph-Request-Timeout-Ms"
38
38
 
39
+ # HTTP header used on datastore requests to identify the caller and request shape.
40
+ # @private
41
+ OPAQUE_ID_HEADER = "X-Opaque-Id"
42
+
39
43
  # Min/max values for the `Int` type.
40
44
  # Based on the GraphQL spec:
41
45
  #
@@ -45,10 +45,46 @@ module ElasticGraph
45
45
  # end
46
46
  def self.define(*attrs, &block)
47
47
  ::Data.define(*attrs) do
48
- # @implements ::Data
48
+ # @implements ConfigData
49
49
  alias_method :__data_initialize, :initialize
50
50
  extend ClassMethods
51
- include InstanceMethods
51
+
52
+ # On JRuby 10.0.4.0, `include`-ing a module in a Data.define block causes
53
+ # subclass instances to have nil fields in certain call patterns. Define the
54
+ # instance methods directly instead of using `include InstanceMethods`.
55
+ # See: https://github.com/jruby/jruby/issues/9327
56
+
57
+ # Overrides `initialize` to apply JSON schema validation.
58
+ def initialize(**config)
59
+ klass = (_ = self.class) # : ClassMethods[::Data]
60
+ validator = klass.validator
61
+ config = validator.merge_defaults(config)
62
+
63
+ if (error = validator.validate_with_error_message(config))
64
+ klass.raise_invalid_config(error)
65
+ end
66
+
67
+ config = config.transform_keys(&:to_sym)
68
+ __skip__ = super(**convert_values(**config))
69
+ end
70
+
71
+ # Overrides `#with` to bypass the normal JSON schema validation that applies in `#initialize`.
72
+ # This is required so that `config.with(...)` can be used on config classes that use the
73
+ # `convert_values` hook to convert JSON data to some custom Ruby type. The custom Ruby type
74
+ # won't pass JSON schema validation, and if we didn't override `with` then we'd get validation
75
+ # failures due to the converted values failing validation.
76
+ def with(**updates)
77
+ (_ = self.class).new_without_validation(**to_h.merge(updates))
78
+ end
79
+
80
+ private
81
+
82
+ # Default implementation of a hook that allows config values to be converted during initialization.
83
+ def convert_values(**values)
84
+ values
85
+ end
86
+
87
+ public
52
88
 
53
89
  class_exec(&(_ = block)) if block
54
90
  end
@@ -148,39 +184,6 @@ module ElasticGraph
148
184
  instance
149
185
  end
150
186
  end
151
-
152
- # @private
153
- module InstanceMethods
154
- # Overrides `initialize` to apply JSON schema validation.
155
- def initialize(**config)
156
- klass = (_ = self.class) # : ClassMethods[::Data]
157
- validator = klass.validator
158
- config = validator.merge_defaults(config)
159
-
160
- if (error = validator.validate_with_error_message(config))
161
- klass.raise_invalid_config(error)
162
- end
163
-
164
- config = config.transform_keys(&:to_sym)
165
- __skip__ = super(**convert_values(**config))
166
- end
167
-
168
- # Overrides `#with` to bypass the normal JSON schema validation that applies in `#initialize`.
169
- # This is required so that `config.with(...)` can be used on config classes that use the
170
- # `convert_values` hook to convert JSON data to some custom Ruby type. The custom Ruby type
171
- # won't pass JSON schema validation, and if we didn't override `with` then we'd get validation
172
- # failures due to the converted values failing validation.
173
- def with(**updates)
174
- (_ = self.class).new_without_validation(**to_h.merge(updates))
175
- end
176
-
177
- private
178
-
179
- # Default implementation of a hook that allows config values to be converted during initialization.
180
- def convert_values(**values)
181
- values
182
- end
183
- end
184
187
  end
185
188
  end
186
189
  end
@@ -0,0 +1,49 @@
1
+ # Copyright 2024 - 2026 Block, Inc.
2
+ #
3
+ # Use of this source code is governed by an MIT-style
4
+ # license that can be found in the LICENSE file or at
5
+ # https://opensource.org/licenses/MIT.
6
+ #
7
+ # frozen_string_literal: true
8
+
9
+ module ElasticGraph
10
+ module Support
11
+ # Helper module to load the graphql gem and optionally graphql-c_parser for better performance.
12
+ # Prints a yellow warning to stderr when c_parser is unavailable (except on JRuby where C extensions don't work).
13
+ #
14
+ # @private
15
+ module GraphQLGemLoader
16
+ # ANSI escape code for yellow text
17
+ YELLOW = "\e[33m"
18
+ RESET = "\e[0m"
19
+
20
+ @warning_printed = false # : bool
21
+
22
+ # Loads the graphql gem and attempts to load graphql/c_parser.
23
+ # If c_parser is unavailable, prints a warning once (unless on JRuby).
24
+ def self.load
25
+ require "graphql"
26
+
27
+ begin
28
+ require "graphql/c_parser"
29
+ rescue LoadError
30
+ print_warning_once
31
+ end
32
+ end
33
+
34
+ def self.print_warning_once
35
+ return if @warning_printed || RUBY_ENGINE == "jruby"
36
+
37
+ @warning_printed = true
38
+ warn "#{YELLOW}[ElasticGraph] For better performance, add `graphql-c_parser` to your Gemfile. See: https://graphql-ruby.org/language_tools/c_parser.html#{RESET}"
39
+ end
40
+
41
+ # Resets warning state; only intended for use in tests.
42
+ def self.reset_warning_state!
43
+ @warning_printed = false
44
+ end
45
+
46
+ private_class_method :print_warning_once, :reset_warning_state!
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,30 @@
1
+ # Copyright 2024 - 2026 Block, Inc.
2
+ #
3
+ # Use of this source code is governed by an MIT-style
4
+ # license that can be found in the LICENSE file or at
5
+ # https://opensource.org/licenses/MIT.
6
+ #
7
+ # frozen_string_literal: true
8
+
9
+ module ElasticGraph
10
+ module Support
11
+ # Builds `X-Opaque-Id` header values from a finite set of readable parts.
12
+ module OpaqueID
13
+ # Builds an `X-Opaque-Id` header value from the provided opaque-id parts.
14
+ #
15
+ # @param parts [Array<String, nil>] opaque-id parts to normalize and join.
16
+ # @return [String, nil] a semicolon-delimited opaque-id header value, or `nil` if no
17
+ # meaningful opaque-id parts remain after normalization.
18
+ def self.build_header(parts)
19
+ header = parts.filter_map do |part|
20
+ normalized = part.to_s.strip
21
+ next if normalized.empty?
22
+
23
+ normalized.gsub(/[;\r\n]/, ",")
24
+ end.join(";")
25
+
26
+ header.empty? ? nil : header
27
+ end
28
+ end
29
+ end
30
+ end
@@ -10,33 +10,38 @@ module ElasticGraph
10
10
  module Support
11
11
  # @private
12
12
  module Threading
13
- # Like Enumerable#map, but performs the map in parallel using one thread per list item.
13
+ # Like Enumerable#map, but performs the map in parallel using one thread per list item
14
+ # when there are multiple items.
14
15
  # Exceptions that happen in the threads will propagate to the caller at the end.
15
16
  # Due to Ruby's GVL, this will never be helpful for pure computation, but can be
16
17
  # quite helpful when dealing with blocking I/O. However, the cost of threads is
17
18
  # such that this method should not be used when you have a large list of items to
18
19
  # map over (say, hundreds or thousands of items or more).
19
20
  def self.parallel_map(items)
20
- threads = _ = items.map do |item|
21
- ::Thread.new do
22
- # Disable reporting of exceptions. We use `value` at the end of this method, which
23
- # propagates any exception that happened in the thread to the calling thread. If
24
- # this is true (the default), then the exception is also printed to $stderr which
25
- # is quite noisy.
26
- ::Thread.current.report_on_exception = false
21
+ return _ = items.map { |item| yield item } if items.size < 2
27
22
 
28
- yield item
23
+ begin
24
+ threads = _ = items.map do |item|
25
+ ::Thread.new do
26
+ # Disable reporting of exceptions. We use `value` at the end of this method, which
27
+ # propagates any exception that happened in the thread to the calling thread. If
28
+ # this is true (the default), then the exception is also printed to $stderr which
29
+ # is quite noisy.
30
+ ::Thread.current.report_on_exception = false
31
+
32
+ yield item
33
+ end
29
34
  end
30
- end
31
35
 
32
- # `value` here either returns the value of the final expression in the thread, or raises
33
- # whatever exception happened in the thread. `join` doesn't propagate the exception in
34
- # the same way, so we always want to use `Thread#value` even if we are just using threads
35
- # for side effects.
36
- threads.map(&:value)
37
- rescue => e
38
- e.set_backtrace(e.backtrace + caller)
39
- raise e
36
+ # `value` here either returns the value of the final expression in the thread, or raises
37
+ # whatever exception happened in the thread. `join` doesn't propagate the exception in
38
+ # the same way, so we always want to use `Thread#value` even if we are just using threads
39
+ # for side effects.
40
+ threads.map(&:value)
41
+ rescue => e
42
+ e.set_backtrace(e.backtrace + caller)
43
+ raise e
44
+ end
40
45
  end
41
46
  end
42
47
  end
@@ -8,7 +8,7 @@
8
8
 
9
9
  module ElasticGraph
10
10
  # The version of all ElasticGraph gems.
11
- VERSION = "1.1.0"
11
+ VERSION = "1.2.0"
12
12
 
13
13
  # Steep weirdly expects this here...
14
14
  # @dynamic self.define_schema
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticgraph-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Myron Marston
@@ -46,6 +46,9 @@ dependencies:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
48
  version: '2.14'
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 2.14.1
49
52
  type: :development
50
53
  prerelease: false
51
54
  version_requirements: !ruby/object:Gem::Requirement
@@ -53,6 +56,9 @@ dependencies:
53
56
  - - "~>"
54
57
  - !ruby/object:Gem::Version
55
58
  version: '2.14'
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.1
56
62
  email:
57
63
  - myron@squareup.com
58
64
  executables: []
@@ -68,6 +74,7 @@ files:
68
74
  - lib/elastic_graph/support/faraday_middleware/support_timeouts.rb
69
75
  - lib/elastic_graph/support/from_yaml_file.rb
70
76
  - lib/elastic_graph/support/graphql_formatter.rb
77
+ - lib/elastic_graph/support/graphql_gem_loader.rb
71
78
  - lib/elastic_graph/support/hash_util.rb
72
79
  - lib/elastic_graph/support/json_schema/meta_schema_validator.rb
73
80
  - lib/elastic_graph/support/json_schema/validator.rb
@@ -75,6 +82,7 @@ files:
75
82
  - lib/elastic_graph/support/logger.rb
76
83
  - lib/elastic_graph/support/memoizable_data.rb
77
84
  - lib/elastic_graph/support/monotonic_clock.rb
85
+ - lib/elastic_graph/support/opaque_id.rb
78
86
  - lib/elastic_graph/support/threading.rb
79
87
  - lib/elastic_graph/support/time_set.rb
80
88
  - lib/elastic_graph/support/time_util.rb
@@ -85,10 +93,10 @@ licenses:
85
93
  - MIT
86
94
  metadata:
87
95
  bug_tracker_uri: https://github.com/block/elasticgraph/issues
88
- changelog_uri: https://github.com/block/elasticgraph/releases/tag/v1.1.0
89
- documentation_uri: https://block.github.io/elasticgraph/api-docs/v1.1.0/
96
+ changelog_uri: https://github.com/block/elasticgraph/releases/tag/v1.2.0
97
+ documentation_uri: https://block.github.io/elasticgraph/api-docs/v1.2.0/
90
98
  homepage_uri: https://block.github.io/elasticgraph/
91
- source_code_uri: https://github.com/block/elasticgraph/tree/v1.1.0/elasticgraph-support
99
+ source_code_uri: https://github.com/block/elasticgraph/tree/v1.2.0/elasticgraph-support
92
100
  gem_category: core
93
101
  rdoc_options: []
94
102
  require_paths:
@@ -107,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
115
  - !ruby/object:Gem::Version
108
116
  version: '0'
109
117
  requirements: []
110
- rubygems_version: 4.0.3
118
+ rubygems_version: 4.0.6
111
119
  specification_version: 4
112
120
  summary: Provides support utilities for other ElasticGraph gems.
113
121
  test_files: []