jpie 1.5.0 → 2.0.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +22 -1
- data/lib/json_api/configuration.rb +36 -11
- data/lib/json_api/controllers/concerns/controller_helpers/error_rendering.rb +6 -7
- data/lib/json_api/controllers/concerns/controller_helpers/resource_setup.rb +2 -3
- data/lib/json_api/controllers/concerns/relationships/serialization.rb +42 -1
- data/lib/json_api/controllers/concerns/relationships/updating.rb +1 -5
- data/lib/json_api/controllers/concerns/resource_actions/crud_helpers.rb +0 -8
- data/lib/json_api/controllers/concerns/resource_actions/filter_validation.rb +3 -7
- data/lib/json_api/controllers/concerns/resource_actions/resource_loading.rb +3 -3
- data/lib/json_api/controllers/concerns/resource_actions/serialization.rb +42 -25
- data/lib/json_api/controllers/concerns/resource_actions.rb +6 -10
- data/lib/json_api/controllers/relationships_controller.rb +2 -3
- data/lib/json_api/errors/parameter_not_allowed.rb +0 -5
- data/lib/json_api/rack/n1_warning.rb +72 -0
- data/lib/json_api/railtie.rb +8 -3
- data/lib/json_api/resources/resource.rb +0 -4
- data/lib/json_api/serialization/concerns/include_filtering.rb +42 -0
- data/lib/json_api/serialization/concerns/includes_serialization.rb +57 -60
- data/lib/json_api/serialization/concerns/links_serialization.rb +12 -4
- data/lib/json_api/serialization/concerns/relationship_processing.rb +1 -5
- data/lib/json_api/serialization/include_path_helpers.rb +34 -0
- data/lib/json_api/serialization/serializer.rb +1 -0
- data/lib/json_api/support/collection_query.rb +1 -2
- data/lib/json_api/support/concerns/condition_building.rb +5 -15
- data/lib/json_api/support/concerns/nested_filters.rb +1 -1
- data/lib/json_api/support/concerns/polymorphic_filters.rb +1 -1
- data/lib/json_api/support/concerns/regular_filters.rb +3 -21
- data/lib/json_api/support/filter_parsing.rb +18 -0
- data/lib/json_api/support/param_helpers.rb +4 -0
- data/lib/json_api/support/query_counter.rb +32 -0
- data/lib/json_api/support/relationship_guard.rb +1 -1
- data/lib/json_api/support/resource_identifier.rb +2 -1
- data/lib/json_api/support/responders.rb +1 -1
- data/lib/json_api/version.rb +1 -1
- data/lib/json_api.rb +3 -1
- metadata +6 -5
- data/lib/json_api/controllers/concerns/resource_actions/preloading.rb +0 -80
- data/lib/json_api/resources/concerns/eager_load_dsl.rb +0 -50
- data/lib/json_api/resources/concerns/preload_dsl.rb +0 -49
- data/lib/json_api/support/response_helpers.rb +0 -10
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module JSONAPI
|
|
4
|
-
module Resources
|
|
5
|
-
module EagerLoadDsl
|
|
6
|
-
extend ActiveSupport::Concern
|
|
7
|
-
|
|
8
|
-
class_methods do
|
|
9
|
-
# Declare associations to always eager-load for this resource
|
|
10
|
-
# @param associations [Array<Symbol>] list of association names to eager-load
|
|
11
|
-
def eager_load(*associations)
|
|
12
|
-
@declared_eager_loads ||= []
|
|
13
|
-
@declared_eager_loads.concat(associations.map(&:to_sym))
|
|
14
|
-
reset_eager_load_associations!
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# Get all eager-load associations including inherited ones
|
|
18
|
-
# @return [Array<Symbol>] frozen array of association names
|
|
19
|
-
def eager_load_associations
|
|
20
|
-
return @eager_load_associations if defined?(@eager_load_associations)
|
|
21
|
-
|
|
22
|
-
@eager_load_associations = build_eager_load_associations.freeze
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def reset_eager_load_associations!
|
|
26
|
-
remove_instance_variable(:@eager_load_associations) if defined?(@eager_load_associations)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
module EagerLoadHelperMethods
|
|
31
|
-
def build_eager_load_associations
|
|
32
|
-
own_associations = @declared_eager_loads || []
|
|
33
|
-
inherited = inherit_eager_load_associations
|
|
34
|
-
(inherited + own_associations).uniq
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def inherit_eager_load_associations
|
|
38
|
-
return [] unless superclass.respond_to?(:eager_load_associations)
|
|
39
|
-
return [] if superclass == JSONAPI::Resource
|
|
40
|
-
|
|
41
|
-
superclass.eager_load_associations
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
included do
|
|
46
|
-
extend EagerLoadHelperMethods
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module JSONAPI
|
|
4
|
-
module Resources
|
|
5
|
-
module PreloadDsl
|
|
6
|
-
extend ActiveSupport::Concern
|
|
7
|
-
|
|
8
|
-
class_methods do
|
|
9
|
-
# Override this method in resource subclasses to preload data before serialization.
|
|
10
|
-
# This is called once with all records before serialization starts.
|
|
11
|
-
# Use this to batch-load data needed by meta methods to avoid N+1 queries.
|
|
12
|
-
#
|
|
13
|
-
# @param records [Array<ActiveRecord::Base>] the records that will be serialized
|
|
14
|
-
# @param context [Hash] optional context (e.g., current user, request params)
|
|
15
|
-
# @return [Hash] a hash of preloaded data keyed by record id
|
|
16
|
-
#
|
|
17
|
-
# @example
|
|
18
|
-
# class WorkstreamResource < ApplicationResource
|
|
19
|
-
# def self.preload_for_serialization(records, context = {})
|
|
20
|
-
# stats = Preloaders::StatsPreloader.call(records: records)
|
|
21
|
-
# { stats: stats }
|
|
22
|
-
# end
|
|
23
|
-
#
|
|
24
|
-
# def meta(...)
|
|
25
|
-
# preloaded = self.class.preloaded_data[record.id]
|
|
26
|
-
# super.merge(loading: preloaded[:stats])
|
|
27
|
-
# end
|
|
28
|
-
# end
|
|
29
|
-
def preload_for_serialization(_records, _context = {})
|
|
30
|
-
# Default implementation does nothing - override in subclasses
|
|
31
|
-
{}
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# Storage for preloaded data (request-scoped via Thread.current)
|
|
35
|
-
def preloaded_data
|
|
36
|
-
Thread.current["#{name}_preloaded_data"] ||= {}
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def preloaded_data=(data)
|
|
40
|
-
Thread.current["#{name}_preloaded_data"] = data
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def clear_preloaded_data!
|
|
44
|
-
Thread.current["#{name}_preloaded_data"] = nil
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|