forest_admin_agent 1.0.0.pre.beta.23 → 1.0.0.pre.beta.24
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/lib/forest_admin_agent/builder/agent_factory.rb +10 -5
- data/lib/forest_admin_agent/routes/abstract_authenticated_route.rb +1 -1
- data/lib/forest_admin_agent/routes/abstract_related_route.rb +2 -2
- data/lib/forest_admin_agent/routes/abstract_route.rb +1 -1
- data/lib/forest_admin_agent/routes/charts/charts.rb +2 -2
- data/lib/forest_admin_agent/routes/resources/count.rb +1 -1
- data/lib/forest_admin_agent/routes/resources/related/associate_related.rb +1 -1
- data/lib/forest_admin_agent/routes/resources/related/dissociate_related.rb +1 -1
- data/lib/forest_admin_agent/routes/resources/related/update_related.rb +1 -1
- data/lib/forest_admin_agent/routes/resources/store.rb +2 -2
- data/lib/forest_admin_agent/serializer/forest_serializer.rb +5 -5
- data/lib/forest_admin_agent/utils/id.rb +1 -1
- data/lib/forest_admin_agent/utils/query_string_parser.rb +1 -1
- data/lib/forest_admin_agent/utils/schema/generator_collection.rb +2 -2
- data/lib/forest_admin_agent/utils/schema/generator_field.rb +13 -13
- data/lib/forest_admin_agent/utils/schema/schema_emitter.rb +1 -1
- data/lib/forest_admin_agent/version.rb +1 -1
- metadata +2 -3
- data/CHANGELOG.md +0 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5366fcae628c5d313080f3218e187b1b5754b884d7e8cc38c85b905b4268e35e
|
|
4
|
+
data.tar.gz: b4778e1a8f354b96b9ce0be00afae2d3688b0565d73026be0b3c0e89425a7aaf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1e150b17814b1d3d7bdf2a25cb4b9cfa9b88a80e29593a4307b452b5096d733360f264e4034da11e835c0c1c24534ea1b84feb7c0e4658dfd0f689ff3b9494bc
|
|
7
|
+
data.tar.gz: e626ef0f2022abc05884b5a529d77269c72bc2c8aa45f3e2d6484021fdd590fe6fc0fce8fdba30869a3ca18c434aad4a2ce614222096ad7e4bf4589848b6c191
|
|
@@ -14,26 +14,31 @@ module ForestAdminAgent
|
|
|
14
14
|
def setup(options)
|
|
15
15
|
@options = options
|
|
16
16
|
@has_env_secret = options.to_h.key?(:env_secret)
|
|
17
|
-
@customizer =
|
|
17
|
+
@customizer = ForestAdminDatasourceCustomizer::DatasourceCustomizer.new
|
|
18
18
|
build_container
|
|
19
19
|
build_cache
|
|
20
20
|
build_logger
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
def add_datasource(datasource)
|
|
24
|
-
|
|
23
|
+
def add_datasource(datasource, options = {})
|
|
24
|
+
@customizer.add_datasource(datasource, options)
|
|
25
|
+
|
|
25
26
|
self
|
|
26
27
|
end
|
|
27
28
|
|
|
29
|
+
def customize_collection(name, handle)
|
|
30
|
+
@customizer.customize_collection(name, handle)
|
|
31
|
+
end
|
|
32
|
+
|
|
28
33
|
def build
|
|
29
|
-
@container.register(:datasource, @customizer)
|
|
34
|
+
@container.register(:datasource, @customizer.datasource)
|
|
30
35
|
send_schema
|
|
31
36
|
end
|
|
32
37
|
|
|
33
38
|
def send_schema(force: false)
|
|
34
39
|
return unless @has_env_secret
|
|
35
40
|
|
|
36
|
-
schema = ForestAdminAgent::Utils::Schema::SchemaEmitter.get_serialized_schema(@customizer)
|
|
41
|
+
schema = ForestAdminAgent::Utils::Schema::SchemaEmitter.get_serialized_schema(@customizer.datasource)
|
|
37
42
|
schema_is_know = @container.key?(:schema_file_hash) &&
|
|
38
43
|
@container.resolve(:schema_file_hash).get('value') == schema[:meta][:schemaFileHash]
|
|
39
44
|
|
|
@@ -14,7 +14,7 @@ module ForestAdminAgent
|
|
|
14
14
|
record = args[:params][:data][:attributes]
|
|
15
15
|
|
|
16
16
|
args[:params][:data][:relationships]&.map do |field, value|
|
|
17
|
-
schema = @collection.fields[field]
|
|
17
|
+
schema = @collection.schema[:fields][field]
|
|
18
18
|
|
|
19
19
|
record[schema.foreign_key] = value['data'][schema.foreign_key_target] if schema.type == 'ManyToOne'
|
|
20
20
|
end
|
|
@@ -4,8 +4,8 @@ module ForestAdminAgent
|
|
|
4
4
|
def build(args = {})
|
|
5
5
|
super
|
|
6
6
|
|
|
7
|
-
relation = @collection.fields[args[:params]['relation_name']]
|
|
8
|
-
@child_collection = @datasource.
|
|
7
|
+
relation = @collection.schema[:fields][args[:params]['relation_name']]
|
|
8
|
+
@child_collection = @datasource.get_collection(relation.foreign_collection)
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
end
|
|
@@ -8,7 +8,7 @@ module ForestAdminAgent
|
|
|
8
8
|
|
|
9
9
|
def build(args)
|
|
10
10
|
@datasource = ForestAdminAgent::Facades::Container.datasource
|
|
11
|
-
@collection = @datasource.
|
|
11
|
+
@collection = @datasource.get_collection(args[:params]['collection_name'])
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def routes
|
|
@@ -141,7 +141,7 @@ module ForestAdminAgent
|
|
|
141
141
|
end
|
|
142
142
|
|
|
143
143
|
def make_leaderboard
|
|
144
|
-
field = @collection.fields[@args[:params][:relationshipFieldName]]
|
|
144
|
+
field = @collection.schema[:fields][@args[:params][:relationshipFieldName]]
|
|
145
145
|
|
|
146
146
|
if field && field.type == 'OneToMany'
|
|
147
147
|
inverse = ForestAdminDatasourceToolkit::Utils::Collection.get_inverse_relation(
|
|
@@ -180,7 +180,7 @@ module ForestAdminAgent
|
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
if collection && filter && aggregation
|
|
183
|
-
rows = @datasource.
|
|
183
|
+
rows = @datasource.get_collection(collection).aggregate(
|
|
184
184
|
@caller,
|
|
185
185
|
filter,
|
|
186
186
|
aggregation,
|
|
@@ -62,7 +62,7 @@ module ForestAdminAgent
|
|
|
62
62
|
origin_value = Collection.get_value(@collection, @caller, parent_id, id)
|
|
63
63
|
record = { relation.origin_key => origin_value, relation.foreign_key => foreign_value }
|
|
64
64
|
|
|
65
|
-
through_collection = @datasource.
|
|
65
|
+
through_collection = @datasource.get_collection(relation.through_collection)
|
|
66
66
|
through_collection.create(@caller, record)
|
|
67
67
|
end
|
|
68
68
|
end
|
|
@@ -52,7 +52,7 @@ module ForestAdminAgent
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def dissociate_or_delete_many_to_many(relation, relation_name, parent_id, is_delete_mode, filter)
|
|
55
|
-
through_collection = @datasource.
|
|
55
|
+
through_collection = @datasource.get_collection(relation.through_collection)
|
|
56
56
|
|
|
57
57
|
if is_delete_mode
|
|
58
58
|
# Generate filters _BEFORE_ deleting stuff, otherwise things break.
|
|
@@ -23,7 +23,7 @@ module ForestAdminAgent
|
|
|
23
23
|
build(args)
|
|
24
24
|
@permissions.can?(:edit, @collection)
|
|
25
25
|
|
|
26
|
-
relation = @collection.fields[args[:params]['relation_name']]
|
|
26
|
+
relation = @collection.schema[:fields][args[:params]['relation_name']]
|
|
27
27
|
parent_id = Utils::Id.unpack_id(@collection, args[:params]['id'])
|
|
28
28
|
|
|
29
29
|
linked_id = if (id = args.dig(:params, :data, :id))
|
|
@@ -32,11 +32,11 @@ module ForestAdminAgent
|
|
|
32
32
|
|
|
33
33
|
def link_one_to_one_relations(args, record)
|
|
34
34
|
args[:params][:data][:relationships]&.map do |field, value|
|
|
35
|
-
schema = @collection.fields[field]
|
|
35
|
+
schema = @collection.schema[:fields][field]
|
|
36
36
|
next unless schema.type == 'OneToOne'
|
|
37
37
|
|
|
38
38
|
id = Utils::Id.unpack_id(@collection, value['data']['id'], with_key: true)
|
|
39
|
-
foreign_collection = @datasource.
|
|
39
|
+
foreign_collection = @datasource.get_collection(schema.foreign_collection)
|
|
40
40
|
# Load the value that will be used as origin_key
|
|
41
41
|
origin_value = record[schema.origin_key_target]
|
|
42
42
|
|
|
@@ -41,8 +41,8 @@ module ForestAdminAgent
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def attributes
|
|
44
|
-
forest_collection = ForestAdminAgent::Facades::Container.datasource.
|
|
45
|
-
fields = forest_collection.fields.select { |_field_name, field| field.type == 'Column' }
|
|
44
|
+
forest_collection = ForestAdminAgent::Facades::Container.datasource.get_collection(object.class.name.demodulize.underscore)
|
|
45
|
+
fields = forest_collection.schema[:fields].select { |_field_name, field| field.type == 'Column' }
|
|
46
46
|
fields.each { |field_name, _field| add_attribute(field_name) }
|
|
47
47
|
return {} if attributes_map.nil?
|
|
48
48
|
attributes = {}
|
|
@@ -104,9 +104,9 @@ module ForestAdminAgent
|
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
def relationships
|
|
107
|
-
forest_collection = ForestAdminAgent::Facades::Container.datasource.
|
|
108
|
-
relations_to_many = forest_collection.fields.select { |_field_name, field| field.type == 'OneToMany' || field.type == 'ManyToMany' }
|
|
109
|
-
relations_to_one = forest_collection.fields.select { |_field_name, field| field.type == 'OneToOne' || field.type == 'ManyToOne' }
|
|
107
|
+
forest_collection = ForestAdminAgent::Facades::Container.datasource.get_collection(object.class.name.demodulize.underscore)
|
|
108
|
+
relations_to_many = forest_collection.schema[:fields].select { |_field_name, field| field.type == 'OneToMany' || field.type == 'ManyToMany' }
|
|
109
|
+
relations_to_one = forest_collection.schema[:fields].select { |_field_name, field| field.type == 'OneToOne' || field.type == 'ManyToOne' }
|
|
110
110
|
|
|
111
111
|
relations_to_one.each { |field_name, _field| add_to_one_association(field_name) }
|
|
112
112
|
|
|
@@ -11,7 +11,7 @@ module ForestAdminAgent
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
result = primary_keys.map.with_index do |pk_name, index|
|
|
14
|
-
field = collection.fields[pk_name]
|
|
14
|
+
field = collection.schema[:fields][pk_name]
|
|
15
15
|
value = primary_key_values[index]
|
|
16
16
|
casted_value = field.column_type == 'Number' ? value.to_i : value
|
|
17
17
|
# TODO: call FieldValidator::validateValue($value, $field, $castedValue);
|
|
@@ -57,7 +57,7 @@ module ForestAdminAgent
|
|
|
57
57
|
return ProjectionFactory.all(collection) unless fields != '' && !fields.nil?
|
|
58
58
|
|
|
59
59
|
fields = fields.split(',').map do |field_name|
|
|
60
|
-
column = collection.fields[field_name.strip]
|
|
60
|
+
column = collection.schema[:fields][field_name.strip]
|
|
61
61
|
column.type == 'Column' ? field_name.strip : "#{field_name.strip}:#{args[:params][:fields][field_name.strip]}"
|
|
62
62
|
end
|
|
63
63
|
|
|
@@ -10,7 +10,7 @@ module ForestAdminAgent
|
|
|
10
10
|
fields: build_fields(collection),
|
|
11
11
|
icon: nil,
|
|
12
12
|
integration: nil,
|
|
13
|
-
isReadOnly: collection.fields.all? { |_k, field| field.type != 'Column' || field.is_read_only },
|
|
13
|
+
isReadOnly: collection.schema[:fields].all? { |_k, field| field.type != 'Column' || field.is_read_only },
|
|
14
14
|
isSearchable: true,
|
|
15
15
|
isVirtual: false,
|
|
16
16
|
name: collection.name,
|
|
@@ -21,7 +21,7 @@ module ForestAdminAgent
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def self.build_fields(collection)
|
|
24
|
-
fields = collection.fields.select do |name, _field|
|
|
24
|
+
fields = collection.schema[:fields].select do |name, _field|
|
|
25
25
|
!ForestAdminDatasourceToolkit::Utils::Schema.foreign_key?(collection, name) ||
|
|
26
26
|
ForestAdminDatasourceToolkit::Utils::Schema.primary_key?(collection, name)
|
|
27
27
|
end
|
|
@@ -10,7 +10,7 @@ module ForestAdminAgent
|
|
|
10
10
|
}.freeze
|
|
11
11
|
|
|
12
12
|
def self.build_schema(collection, name)
|
|
13
|
-
type = collection.fields[name].type
|
|
13
|
+
type = collection.schema[:fields][name].type
|
|
14
14
|
|
|
15
15
|
case type
|
|
16
16
|
when 'Column'
|
|
@@ -26,7 +26,7 @@ module ForestAdminAgent
|
|
|
26
26
|
private
|
|
27
27
|
|
|
28
28
|
def build_column_schema(collection, name)
|
|
29
|
-
column = collection.fields[name]
|
|
29
|
+
column = collection.schema[:fields][name]
|
|
30
30
|
is_foreign_key = ForestAdminDatasourceToolkit::Utils::Schema.foreign_key?(collection, name)
|
|
31
31
|
|
|
32
32
|
{
|
|
@@ -74,10 +74,10 @@ module ForestAdminAgent
|
|
|
74
74
|
|
|
75
75
|
def build_many_to_many_schema(relation, collection, foreign_collection, base_schema)
|
|
76
76
|
target_name = relation.foreign_key_target
|
|
77
|
-
target_field = foreign_collection.fields[target_name]
|
|
78
|
-
through_schema = collection.datasource.
|
|
79
|
-
foreign_schema = through_schema.fields[relation.foreign_key]
|
|
80
|
-
origin_key = through_schema.fields[relation.origin_key]
|
|
77
|
+
target_field = foreign_collection.schema[:fields][target_name]
|
|
78
|
+
through_schema = collection.datasource.get_collection(relation.through_collection)
|
|
79
|
+
foreign_schema = through_schema.schema[:fields][relation.foreign_key]
|
|
80
|
+
origin_key = through_schema.schema[:fields][relation.origin_key]
|
|
81
81
|
|
|
82
82
|
base_schema.merge(
|
|
83
83
|
{
|
|
@@ -96,8 +96,8 @@ module ForestAdminAgent
|
|
|
96
96
|
|
|
97
97
|
def build_one_to_many_schema(relation, collection, foreign_collection, base_schema)
|
|
98
98
|
target_name = relation.origin_key_target
|
|
99
|
-
target_field = collection.fields[target_name]
|
|
100
|
-
origin_key = foreign_collection.fields[relation.origin_key]
|
|
99
|
+
target_field = collection.schema[:fields][target_name]
|
|
100
|
+
origin_key = foreign_collection.schema[:fields][relation.origin_key]
|
|
101
101
|
|
|
102
102
|
base_schema.merge(
|
|
103
103
|
{
|
|
@@ -115,8 +115,8 @@ module ForestAdminAgent
|
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
def build_one_to_one_schema(relation, collection, foreign_collection, base_schema)
|
|
118
|
-
target_field = collection.fields[relation.origin_key_target]
|
|
119
|
-
key_field = foreign_collection.fields[relation.origin_key]
|
|
118
|
+
target_field = collection.schema[:fields][relation.origin_key_target]
|
|
119
|
+
key_field = foreign_collection.schema[:fields][relation.origin_key]
|
|
120
120
|
|
|
121
121
|
base_schema.merge(
|
|
122
122
|
{
|
|
@@ -134,7 +134,7 @@ module ForestAdminAgent
|
|
|
134
134
|
end
|
|
135
135
|
|
|
136
136
|
def build_many_to_one_schema(relation, collection, foreign_collection, base_schema)
|
|
137
|
-
key_field = collection.fields[relation.foreign_key]
|
|
137
|
+
key_field = collection.schema[:fields][relation.foreign_key]
|
|
138
138
|
|
|
139
139
|
base_schema.merge(
|
|
140
140
|
{
|
|
@@ -152,8 +152,8 @@ module ForestAdminAgent
|
|
|
152
152
|
end
|
|
153
153
|
|
|
154
154
|
def build_relation_schema(collection, name)
|
|
155
|
-
relation = collection.fields[name]
|
|
156
|
-
foreign_collection = collection.datasource.
|
|
155
|
+
relation = collection.schema[:fields][name]
|
|
156
|
+
foreign_collection = collection.datasource.get_collection(relation.foreign_collection)
|
|
157
157
|
|
|
158
158
|
relation_schema = {
|
|
159
159
|
field: name,
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: forest_admin_agent
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.0.pre.beta.
|
|
4
|
+
version: 1.0.0.pre.beta.24
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matthieu
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2023-12-
|
|
12
|
+
date: 2023-12-18 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|
|
@@ -218,7 +218,6 @@ extensions: []
|
|
|
218
218
|
extra_rdoc_files: []
|
|
219
219
|
files:
|
|
220
220
|
- ".rspec"
|
|
221
|
-
- CHANGELOG.md
|
|
222
221
|
- README.md
|
|
223
222
|
- Rakefile
|
|
224
223
|
- forest_admin
|